Click to See Complete Forum and Search --> : STL in a DLL: Problems that may occur


MrDoomMaster
March 25th, 2008, 05:29 PM
Hi,

I'm just curious if it is safe to use STL in the implementation and interface of a library which is compiled into a shared library (DLL). I remember years ago trying this and it never worked because I was at some point required to also export STL container classes.

Since STL container classes are pure template classes, it wouldn't make sense to have to export them since templates cannot be generated at runtime. I am also unsure if the C++03 standard states that statics may not be used in the implementation of STL. If statics can be used, for example, by std::vector, you could run into memory management issues if I am not mistaken.

Clarification on this matter would be greatly appreciated!

MrViggy
March 25th, 2008, 05:50 PM
The issue with exporting interfaces from DLL's that use STL isn't an issue with the standard. The problem was (and may still be, I don't know) the implementation of the STL that Visual Studio used (they did use static variables).

http://support.microsoft.com/default.aspx?scid=kb;EN-US;168958

Viggy

STLDude
March 25th, 2008, 06:14 PM
Bigger issue is that you have to make sure that dll's and executable will use the same STL implementation and are compiled with the same settings. If you absolutely can assure that, than it's doable. Whether it's a right think or not, you have to decide that.

MrDoomMaster
March 25th, 2008, 06:25 PM
Bigger issue is that you have to make sure that dll's and executable will use the same STL implementation and are compiled with the same settings. If you absolutely can assure that, than it's doable. Whether it's a right think or not, you have to decide that.

I was going to grab STLPort and use that instead of Microsoft's implementation to help make this doable. However, STLPort doesn't support VS9 and thus is getting very difficult to compile, but that's out of the scope of this thread...

STLDude
March 25th, 2008, 07:00 PM
I would just stick with Microsoft STL, since I think STLPort is not maintained anymore.

As far as you original question, I myself do share STL across DLL's and executable, but all of them are build by me (and I'm using Microsoft one).

MrDoomMaster
March 25th, 2008, 07:17 PM
I would just stick with Microsoft STL, since I think STLPort is not maintained anymore.

This can't be an accurate statement, as version 5.1.5 was released on January 19th, 2008 according to their Sourceforge website.

STLDude
March 25th, 2008, 07:23 PM
Hence I said
since I think STLPort is not maintained anymore.
and you seem to did the leg work.