December 6, 2007

Exporting STL member variables in a DLL (C/C++)

Filed under: C/C++ — mdzahidh @ 9:35 am

Have you ever encountered one such dreaded warning messages ( warning C4251 ):

D:\Microsoft Visual Studio .NET 2003\Vc7\include\list(93) : warning C4251: ‘std::_List_nod<_Ty,_Alloc>::_Alnod’ : class ‘std::allocator<_Ty>’ needs to have dll-interface to be used by clients of class ‘std::_List_nod<_Ty,_Alloc>’

And did you ever wonder what caused it or perhaps how to solve this warning problem. Honestly, I still could not figure out the right workaround with STL containers but found this Microsoft Link useful.

Happy Coding.




  1. very interesting, but I don’t agree with you

    Comment by Idetrorce — December 16, 2007 @ 12:16 am | Reply

  2. It illustrates a grave, known incompatibility between STL and dynamic libraries.
    DLL is binary. But STL generates methods lazily, only when they are used.
    Thus, when you link a DLL, STL doesn’t generate any of the functions a client program will need.
    Furthermore, STL is deeply layered, with base classes and base-base classes, and so on.
    So you can not force STL to generate the methods required for shared binaries. There are too many, and they are too fine-grained.
    Deep, hideous compiler changes are necessary.

    Comment by wayne isaacs — January 24, 2009 @ 6:06 am | Reply

  3. I’m not that much of a internet reader to be honest but your
    blogs really nice, keep it up! I’ll go ahead and bookmark your website to come back later on. Cheers

    Comment by http://almesryoon.com/forum/entry.php?13274-Is-True-Magic-Dark-White-Or-some-different-Entirely — May 1, 2013 @ 4:16 am | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.