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

人盡茶涼 提交于 2019-12-05 09:35:24

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.

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

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)

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