You can pass stl objects between DLLs and support different compilers if you are careful when you instantiate each type of stl. You need some intelligent DLLEXPORT macros β I use the following set to successfully support VC and gcc.
#ifdef WIN32 #ifdef MYDLLLIB_EXPORTS // DLL export macros #define MYDLLLIB_API __declspec(dllexport) #define MYDLLLIB_TEMPLATE #else #define MYDLLLIB_API __declspec(dllimport) #define MYDLLLIB_TEMPLATE extern #endif #else // Not windows --- probably *nix/bsd #define MYDLLLIB_API #ifdef MYDLLLIB_EXPORTS #define MYDLLLIB_TEMPLATE #else #define MYDLLLIB_TEMPLATE extern #endif #endif // WIN32
When compiling your DLL, define MYDLLLIB_EXPORTS. In a DLL, you can instantiate each type of stl that you want to use, such as lists or string vectors
MYDLLLIB_TEMPLATE template class MYDLLLIB_API std::vector<std::string>; MYDLLLIB_TEMPLATE template class MYDLLLIB_API std::list<std::string>;
Consumers of your DLL (for which MYDLLLIB_EXPORTS are not defined) will see
extern template class __declspec(dllimport) std::vector<std::string>;
and use the binary code exported from your DLL, instead of creating your own.
mcdave
source share