Exporting STL objects from a DLL

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?
 
B

Bruno van Dooren

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.
 
S

Sheng Jiang[MVP]

The other way is to hide your implementation details, export interfaces
instead of classes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top