[CMake] Proper way to export a library

Cyrille Faucheux cyrille.faucheux at gmail.com
Sat Nov 2 13:38:26 EDT 2013


Wow, this thread has gone wild...

To clarify my case:
The prototype of each functions I want to export is prefixed by a
MYPROJECT_EXTERNAL preprocessor constant. With Visual Studio, this constant
is, by default, set to __declspec(dllimport). This way, I can link against
the shared version of this library without having to define anything.

When compiling this library as a shared library, I have to define a
MYPROJECT_EXPORT_SHARED constant, which will set MYPROJECT_EXTERNAL to
__declspec(dllimport).

But if I want to build/link against a static version of this library, I
need to pass a MYPROJECT_STATIC as a define in order to set
MYPROJECT_EXTERNAL to nothing.



More information about the CMake mailing list