STL in a DLL

Started by
4 comments, last by 999999999 18 years, 9 months ago
I found a few other people who posted about this, but the threads never seemed to end with a solution. I'm trying to use STL (i.e. std::string, std::vector, etc...) inside a DLL. However I always seem to get errors about std::insertnamehere not being exported. I've search all over for a soultion to this and have found a lot of information. I've followed instructions on msdn and in threads here to the letter but nothing seems to work. I can remove one error only to create more... I'm beginning to think that I just can't use STL in a DLL... Is this the case?
Advertisement
No, you can use STL containers in DLLs, but it's not worth the effort (at least in my opinion). First off you have to make sure that the application using the DLL is compiled with the same compiler and STL version (usually not a problem), then you have to make sure that both the application and the DLL share the C runtime. In MSVC this accomplished by building both EXE and DLL with the Multithreaded DLL version of the C Runtime, or the Multithreaded Debug DLL version of the C Runtime for a debug build. Then you need to make sure to export the STL class from the DLL properly. Here is an article describing the syntax necessary. Also if you use custom allocators, you have to make sure any static members of the allocators are exported properly too.

Edit: Also, if you have multiple DLLs using the STL classes, you should then either create a new DLL that the other DLLs use to import the STL classes from, or otherwise mark one of the DLLs as holding the master copies of the STL code.
Simply switching to stlport does most of that for you, but you will still have to keep your build settings consistent wether you are using the stl or not.
I don't understand what you mean, I am using the standard STL (for the lack of being lazy and not switching to stlport yet) and it works perfectly fine in a DLL. All you need to do is simply include the header files, and boom, it works like magik. But I also don't use multiple DLLs (yet) and don't pass STL containers across DLLs.
-John "bKT" Bellone [homepage] [[email=j.bellone@flipsidesoftware.com]email[/email]]
You can use STL perfectly fine in an DLL. The problems arise when you pass STL containers across DLL boundaries and (try to) modify the contents.

If you really need that you can provide a custom allocator to those containers which uses GlobalAlloc for example.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I use STL in DLLs with no problems, but I have never tried to export those symbols

This topic is closed to new replies.

Advertisement