Exporting STL objects from a DLL

  • Thread starter Thread starter Grey Alien
  • Start date Start date
G

Grey Alien

I have an exported class which delegates to a std::map variable. When
building, I get the warning that I should export std::map for clients of
my DLL to be able to work properly.

HOWEVER, according to this:

See: http://support.microsoft.com/kb/168958

Relevant text is:
"The only STL container that can currently be exported is vector. The
other containers (that is, map, set, queue, list, deque) all contain
nested classes and cannot be exported."

The article was last reviewed in September 2005 - I wanted to know if it
is now possible to export std::map from a DLL?
 
I have an exported class which delegates to a std::map variable. When
building, I get the warning that I should export std::map for clients of my
DLL to be able to work properly.

HOWEVER, according to this:

See: http://support.microsoft.com/kb/168958

Relevant text is:
"The only STL container that can currently be exported is vector. The
other containers (that is, map, set, queue, list, deque) all contain
nested classes and cannot be exported."

The article was last reviewed in September 2005 - I wanted to know if it
is now possible to export std::map from a DLL?

You don't export STL classes as such because there is nothing to export.
They are only templates until they are specialized. Templates themselves
cannot be exported.

You can use STL classes in your exported interface, but then you have to be
sure that whoever uses that interface uses the same version of STL and
compiler that you did. Otherwise you will have hard to dignose problems
because the caller's understanding of what std::list<int> looks like is
different than what the callee thinks it looks like.

In the case of the warning you mentioned, the only thing you can do is to
suppress the warning and document that the users of your libary have to use
the same version of the STL and compiler.
 
The other way is to hide your implementation details, export interfaces
instead of classes.
 
Back
Top