[Cmake] import/exports for shared libraries

William A. Hoffman billlist at nycap.rr.com
Wed, 05 May 2004 08:35:48 -0400


That is what the lib_EXPORTS defines are for.

If the library is always shared then you can do something like this:

-------sharedLibraryImports.h-----
#if defined(_WIN32) || defined(WIN32) /* Win32 version */
#ifdef CMakeTestLibraryShared_EXPORTS
#  define CMakeTest_EXPORT __declspec(dllexport)
#else
#  define CMakeTest_EXPORT __declspec(dllimport)
#endif
#else
/* unix needs nothing */
#define CMakeTest_EXPORT
#endif

CMakeTest_EXPORT int sharedFunction();


If it can be built both shared and static you want to wrap
the whole thing in a new define that tells if the project
was built shared or static.   It is best to configure a header
file with cmake that uses the BUILD_SHARED_LIBS flag to create
a define.   Then include that file in the executable.  

BTW, this is all documented in "Mastering CMake".

-Bill


At 05:32 AM 5/5/2004, sylvain.prat wrote:
>Hi,
>
>I was wondering how to properly set import/exports for dll/shared libraries in a cross-platform manner :
>
>- I see a *library*_EXPORTS while compiling some shared libraries : there's nothing about this in the documentation. So, what is this flag ? Can I use it to set up the export directive (I mean since which version of cmake it appears) ? I currently think  that *library*_EXPORTS  can help to set the dllexport/no-export flag but how to set the import flag while using shared libraries in executables ?
>- how to set the exports/imports directives ? I used to set these :
>
>#if (defined(_WIN32) || defined(__CYGWIN__))
>#  if defined(MYLIB_MAKEDLL)
>#    define MYLIB_EXPORT __declspec(dllexport)
>//#  define MYLIB_EXTERN
>#  elif defined(MYLIB_USEDLL)
>#    define MYLIB_EXPORT __declspec(dllimport)
>//#  define MYLIB_EXTERN //extern
>#  endif
>#endif
>
>#ifndef MYLIB_EXPORT
>#  define MYLIB_EXPORT
>#endif
>//#ifndef MYLIB_EXTERN
>
>//#define MYLIB_EXTERN
>//#endif
>
>- how can i automaticaly tell cmake to build my project with consistent link options ?
>
>Thanks in advance
>
>
>Sylvain PRAT Accédez au courrier électronique de La Poste : www.laposte.net ; 3615 LAPOSTENET (0,34€/mn) ; tél : 08 92 68 13 50 (0,34€/mn) 
>
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake