How can i build project in visual studio 2012 on both way(dll and lib) together

送分小仙女□ 提交于 2020-01-02 05:02:23

问题


I managed to set up build project in dll mode and in library mode but not together:

for build in dll:

  • project->properties->Configuration Type: Dynamic Library (.dll)
  • project->properties->Target Extension: .dll

for build in library:

  • project->properties->Configuration Type: Static library (.lib)
  • project->properties->Target Extension: .lib

it is possible to build both of them together?


回答1:


Yes, you can have single project that can be used for .dll and .lib.

Steps to be followed:

  1. Visual Studio will provide you Debug and Release solution configurations. Create custom configurations for lib and dll (i.e. lib-release, dll-release).
  2. For each configuration set different project type and set export symbols. i.e. for lib-release define LIB_CONFIG and don't set it for dll-release.
  3. In code file use LIB_CONFIG with #IFDEF to include/exclude project type specific code. IF some part of code is lib specific the add it in #ifdef LIB_CONFIG...#endif, and if it is dll specific add it in #ifndef LIB_CONFIG...#endif.
  4. 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.




回答2:


During creation of new project in Visual Studio, make sure you check on "Export Symbols"




回答3:


No. You must have two projects in your solution (using the same source files). Don't forget to have different names for your 2 .lib files.

EDIT: use some trick to not include a DllMain function in your static lib (either some #ifdef, or a separate file not added to the static project)



来源:https://stackoverflow.com/questions/20853577/how-can-i-build-project-in-visual-studio-2012-on-both-waydll-and-lib-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!