Is there a way to automatically make the library static or dynamic?

I know it might be a long shot, but here it goes. I have several active projects, each with a subproject library that gets compiled when the main project is compiled. These libraries are dynamic, but recently there has been a problem that may require these libraries (most of them shared between projects) to become static rather than dynamic.

Now I'm sure someone has devised a system where I could create a library that could be linked as static to project or dynamic, with something like a simple preprocessor directive or something. If not, I will kill the dream.

edit:

looks like CMake, maybe it is, however, apart from making things, I would also like to facilitate __declspec (dllimport) and __declspec (dllexport) from my code - so that I can automatically switch between static and dynamic. While this is fairly easy to do with preprocessor macros, I thought maybe there might be some form of system already in use by people?

+1


a source to share


3 answers


I like to use CMake to avoid these problems.



+2


a source


If you want it to be cross platform you will have to use a tool like SCons or Make and set up different compiler / linker arguments based on whatever command variables you pass. You will need to do this for each platform and combined link type.



In Visual Studio Configuration Manager (you are not limited to just release and debug) and then you can have ReleaseStatic and ReleaseDynamic and any other configurations you can dream of. Then you just install the correct compilers and linkers for each configuration.

+1


a source


Download the cURL source code and see how it is configured. It can create libcurl for DLL or static on Windows, and static or shared object on Unix.

-1


a source







All Articles