I've got a large visual studio solution with ~50 projects. There are configurations for StaticDebug, StaticRelease, Debug and Release. Some libraries are needed in both dll and static lib form. To get them, we rebuild the solution with a different configuration. The Configuration Manager window is used to setup which projects need to build in which flavours, static lib, dynamic dll or both.
This can by quite tricky to manage and it's a bit annoying to have to build the solution multiple times and select the configurations in the right order. Static versions need building before non-static versions.
I'm wondering, instead of this current scheme, might it be simpler to manage if, for the projects I needed to produce both a static lib and dynamc dll, I created two projects. Eg:
I could either make both of these projects reference all the same files and build them twice, or I'm wondering, would it be possible to build CoreLib and then get CoreDll to link it to generate the dll?
I guess my question is, do you have any advice on how to structure your projects in this kind of situation?
Thanks.
Make a copy your original project file in explorer as CoreLib.vcxproj (in case of other VS check the appropiate extension)
Add CoreLib.vcxproj as an existing project to your solution and save your solution.
Go to the properties->Configuration Properties->General of CoreLib.
Select all Configurations (left upper corner).
Change property Configuration type to static library.
Change property Target Extension to .lib .
Append to property Intermediate directory for example \Lib\ .
Go to the properties->Configuration Properties->C/C++->Preporcessor
Select Debug Configuration (left upper corner).
Now edit the property Preprocessor Definitions and change the line _USRDLL into _USRLIB
Select Release Configuration (left upper corner).
Now edit the property Preprocessor Definitions and change the line _USRDLL into _USRLIB
In your header-file you should have something like the following:
#ifdef MyDll_EXPORTS
#define MyDll_API __declspec(dllexport)
#else
#define MyDll_API __declspec(dllimport)
#endif
change it into something like the following :
#ifdef MyDll_EXPORTS
#ifdef _USRLIB
#define MyDll_API
#else
#define MyDll_API __declspec(dllexport)
#endif
#else
// Here must deploy your own logic whether static or dynamic linking is used.
// read my comment below
#define MyDll_API __declspec(dllimport)
#endif
Now your Build generates your original dll and import lib as well as a new static lib !
Maybe you could check what a build system like CMake produces for this case. I'm guessing it will generate two projects for each case. But by creating the solution this way it could possibly save you a lot of work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With