1

My class contains a std::map<std::string, int> and a std::map<std::string, std::map<std::string, int>>. And I'm trying to export the STL Objects. I was following the example given here

#include <map>
#include <string>
#include <vector>

#ifdef AIRCRAFTCONFIGDLL_EXPORTS
#define AIRCRAFTCONFIGDLL_API __declspec(dllexport)
#define EXPIMP_TEMPLATE
#else
#define AIRCRAFTCONFIGDLL_API __declspec(dllimport)
#define EXPIMP_TEMPLATE
#endif

EXPIMP_TEMPLATE template struct AIRCRAFTCONFIGDLL_API std::less<std::string>;
EXPIMP_TEMPLATE template class AIRCRAFTCONFIGDLL_API std::allocator<std::string>;
EXPIMP_TEMPLATE template class AIRCRAFTCONFIGDLL_API std::allocator<std::pair<const std::string, int>>;
EXPIMP_TEMPLATE template class AIRCRAFTCONFIGDLL_API std::map<std::string, int>;
EXPIMP_TEMPLATE template class AIRCRAFTCONFIGDLL_API std::allocator<std::pair<const std::string, std::map<std::string, int>>>;
EXPIMP_TEMPLATE template class AIRCRAFTCONFIGDLL_API std::map<std::string, std::map<std::string, int>>;

class AIRCRAFTCONFIGDLL_API CAircraftConfig
{
.
.
.

But all the sudden my warnings got really hairy. Do I need to include all these crazy allocators or is there a better way?

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(81): warning C4251: 'std::_Tree_nod<_Traits>::_Alnod' : class 'std::allocator<_Ty>' needs to have dll-interface to be used by clients of class 'std::_Tree_nod<_Traits>'
1>          with
1>          [
1>              _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1>          ]
1>          and
1>          [
1>              _Ty=std::_Tree_nod<std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>>::_Node
1>          ]
1>          and
1>          [
1>               _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1>          ]
1>          c:\uaepgjtac\release_3.x-development\pilotstationballisticlibrary\aircraftconfigdll\aircraftconfigdll.h(20) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1>          with
1>          [
1>              _Kty=std::string,
1>              _Ty=int
1>          ]
cdhowie
  • 158,093
  • 24
  • 286
  • 300
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • 1
    `I'm trying to export the STL Objects` Not the best idea. It could only work if the DLL's client is built with the same version of the same compiler using the same settings - which kind of defeats the purpose of a DLL. The binary layout of STL objects varies quite a bit between versions and options (e.g. debug vs release). And when two modules try to share objects they don't agree on the binary layout of, the program will go boom. Define an interface, export it, have your class derive from it, export a factory function that creates an instance of the class and returns its interface pointer. – Igor Tandetnik Oct 29 '14 at 14:45
  • @IgorTandetnik I'm getting that feeling from asking this question: http://stackoverflow.com/questions/26628597/warning-c4231-vs-c4251 and from reading here: http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL – Jonathan Mee Oct 29 '14 at 14:49
  • @IgorTandetnik Could you formalize this into an answer? I had forgotten all about this question, but now I'm getting other answers and I'd like to accept your answer cause that's the right one. – Jonathan Mee Feb 11 '15 at 20:46
  • http://stackoverflow.com/questions/767579/exporting-classes-containing-std-objects-vector-map-etc-from-a-dll (listed in Related section on the right) discusses these issues at some lengths. I don't really have much to add. – Igor Tandetnik Feb 12 '15 at 00:26
  • @IgorTandetnik Sounds like maybe this is a duplicate? I'm reading over the info, but if you think so too can you mark as well? – Jonathan Mee Feb 12 '15 at 02:51

0 Answers0