Here's a portable, common way to handle WIN32 exports. It will generate .lib on Windows using Visual Studio or other compiler (e.g. MinGW).
In the project that creates the library, define the preprocessor directive SOMECLASS_LIBRARY ... resulting in usage of the dllexport rule.
In the project that includes the library, it will automatically use the dllimport rule.
In header file someClassExport.h
#ifndef _SOMECLASS_EXPORT_
#define _SOMECLASS_EXPORT_
#if defined(WIN32) || defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
#ifdef SOMECLASS_LIBRARY
#define SOMECLASS_EXPORT __declspec(dllexport)
#else
#define SOMECLASS_EXPORT __declspec(dllimport)
#endif
#else
#define SOMECLASS_EXPORT
#endif
#endif // _SOMECLASS_EXPORT_
#ifndef _SOMECLASS_EXPORT_
#define _SOMECLASS_EXPORT_
#if defined(WIN32) || defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
#ifdef SOMECLASS_LIBRARY
#define SOMECLASS_EXPORT __declspec(dllexport)
#else
#define SOMECLASS_EXPORT __declspec(dllimport)
#endif
#else
#define SOMECLASS_EXPORT
#endif
#endif // _SOMECLASS_EXPORT_
To copy to clipboard, switch view to plain text mode
In header file someClass.h
#ifndef _SOMECLASS_
#define _SOMECLASS_
#include "someClassExport.h"
// If wanting to export whole class ...
class SOMECLASS_EXPORT cSomeClass
{
public:
int foo(void);
}
// Or, if wanting to export only specified methods of class ...
class cSomeClass
{
public:
SOMECLASS_EXPORT int foo(void);
};
#endif // _SOMECLASS_
#ifndef _SOMECLASS_
#define _SOMECLASS_
#include "someClassExport.h"
// If wanting to export whole class ...
class SOMECLASS_EXPORT cSomeClass
{
public:
int foo(void);
}
// Or, if wanting to export only specified methods of class ...
class cSomeClass
{
public:
SOMECLASS_EXPORT int foo(void);
};
#endif // _SOMECLASS_
To copy to clipboard, switch view to plain text mode
Bookmarks