enable windows DLL build
We need to add appropriate declspec
to class and function declarations to allow a DLL build on windows. This is straightforward but unfortunately very tedious.
First create a header (e.g. nsxlib/dll.h
) with the following contents
#ifndef NSX_DLL_
#define NSX_DLL_
#ifdef _WIN32 && NSX_SHARED
#ifdef NSX_BUILD_DLL
#define NSX_API __declspec(dllexport)
#else
#define NSX_API __declspec(dllimport
#endif
#else
#define NSX_API
#endif
#endif
Now modify the cmake so that if a shared library is being build, NSX_SHARED
is added to compiler definition, and during the Windows build of nsxlib NSX_BUILD_DLL
is added to the compiler definitions.
Now, the tedious part: for every class header, add #include "nsxlib/dll.h"
as the first line after the copyright header, and change every class declaration
class A {
//...
};
to
NSX_API class A {
//...
};