本文介绍了我如何可以在visual studio 2012中以两种方式(dll和lib)一起构建项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设法在dll模式和图书馆模式下建立项目,但不在一起:
I managed to set up build project in dll mode and in library mode but not together:
用于构建dll:
- project-> properties->配置类型:动态库(.dll)
- project-> properties->目标扩展名:.dll
在图书馆中建立:
- project-> properties->配置类型:静态库(.lib)
- project-> properties->目标扩展名:.lib
可以将它们一起构建?
推荐答案
是的,你可以单个项目可以用于.dll和.lib。
Yes, you can have single project that can be used for .dll and .lib.
要遵循的步骤:
- Visual Studio将为您提供Debug和Release解决方案
配置。为lib和dll创建自定义配置(即
lib-release,dll-release)。 - 对于每个配置设置不同的项目类型并设置导出
符号。即lib-release定义LIB_CONFIG,不要为
dll-release设置。 - 在代码文件中使用带有#IFDEF的LIB_CONFIG来包含/排除项目
键入特定代码。如果某些部分代码是lib特定的,则在#ifdef LIB_CONFIG ...#endif中添加
,如果是dll,则将其添加到
#ifndef LIB_CONFIG ...#endif。 - 更改Active Solution配置后编译项目。即
更改为lib-release,如果您想要.lib文件。
- Visual Studio will provide you Debug and Release solutionconfigurations. Create custom configurations for lib and dll (i.e.lib-release, dll-release).
- For each configuration set different project type and set exportsymbols. i.e. for lib-release define LIB_CONFIG and don't set it fordll-release.
- In code file use LIB_CONFIG with #IFDEF to include/exclude projecttype specific code. IF some part of code is lib specific the add itin #ifdef LIB_CONFIG...#endif, and if it is dll specific add it in#ifndef LIB_CONFIG...#endif.
- Compile project after changing Active solution configuration. i.e.change to lib-release, if you want to have .lib file.
我希望这将有助于您。请让我知道您的意见。
I hope this will help you. Please let me know your feedback.
这篇关于我如何可以在visual studio 2012中以两种方式(dll和lib)一起构建项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!