问题
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:
- Visual Studio will provide you Debug and Release solution configurations. Create custom configurations for lib and dll (i.e. lib-release, dll-release).
- 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.
- 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.
- 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