问题
Let's say I write a DLL in C++ and would like to export a method which takes a std::vector parameter. Can I hope for any binary compatibility between different STL versions?
回答1:
If you mean between the versions included with updated versions of the same compiler, yes, it can (and will) work in some cases, but you have to be careful. There are also a few special cases, such as the Intel and Microsoft compilers on Windows -- Intel is pretty careful to maintain binary compatibility, and at least when I've tried it, it's always worked quite nicely.
For most other cases, the answer is no.
回答2:
I'm not aware of any guarantees of compatibility between versions, not even between release and debug on the same compiler.
One solution is to create a wrapper for the vector. Create a class which has all the functions you require from the container, and implement them in terms of operations on the private vector which is the only member of the class. Keep all the class code in the DLL.
回答3:
Absolutely not! You can't even rely on the same version of the STL being compatible if it was compiled with a different version of the same compiler.
来源:https://stackoverflow.com/questions/5736289/binary-compatibility-of-stl-containers