Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 302
oshribm Avatar asked Dec 31 '13 07:12

oshribm


3 Answers

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.

like image 133
Elixir Techne Avatar answered Nov 14 '22 23:11

Elixir Techne


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

like image 26
Digital_Reality Avatar answered Nov 15 '22 00:11

Digital_Reality


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)

like image 24
manuell Avatar answered Nov 14 '22 23:11

manuell