[Cmake] Building DLLs on Windows

Bill Hoffman bill.hoffman at kitware.com
Mon Jan 13 08:33:08 EST 2003


def files work if you add them to the source list for a library.
However, there is now way to automatically generate them right now.
The preferred method is to use the __declspec(dllexport) directive.
__declspec(dllexport) is what you want if you want to export symbols
out of a library.   If you tried dllimport that would explain why it did
not work.

Here is an example from on of cmakes tests:
-----sharedFile.h------
#if 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();


-----sharedFile.cxx-------
#include "sharedFile.h"

int sharedFunction()
{
  return 1;
}






More information about the CMake mailing list