5

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?

pic11
  • 14,267
  • 21
  • 83
  • 119
quant_dev
  • 6,181
  • 1
  • 34
  • 57

3 Answers3

6

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.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • +1 -- but that still doesn't mean it will be portable. Things like exception handling scheme can change between compiler versions or compiler switches too, and you have no control over those things. Generally, if you want binary compatibility then you need to use a C interface. (For example, on MSVC++ the `/SAFESEH`, and `/Eh` switches change the binary level exception model, and I believe at least `/GS` does too) – Billy ONeal Apr 20 '11 at 20:47
4

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.

Ferruccio
  • 98,941
  • 38
  • 226
  • 299
3

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.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111