Creating program libraries in Windows and LINUX [C++] Creating program libraries in Windows and LINUX [C++] windows windows

Creating program libraries in Windows and LINUX [C++]


We specify __declspec(dllexport) for class:

#define EXPORT_XX __declspec(dllexport)class EXPORT_XX A{};

You can then check for platform and only define the macro on windows. E.g.:

#ifdef WIN32#define EXPORT_XX __declspec(dllexport)#else#define EXPORT_XX#endif

We mostly build static libraries so there might be more stuff to do for dynamic libs but the concept is the same - use preprocessor macro to define string that you need to insert into Windows code.


Another alternative is to just use a .def file for your windows project. This file specifies the DLL exports, so you won't have to mess up your code base. (But macros are definately the way to go if you want to avoid the extra file.)


You can use #ifdef preprocessor directive for conditional compiling. For example:

#ifdef WIN32    // Win32 specific code#else    // Elsewhere#endif