none
STL compatibility across different versions of CRT

    Question

  • Hi all,

    I have a dll build with VC++ 2003 using code having some STL objects (including std::string).

    1. Does my STL objects causes any problems if it is used in a dll comipled with different/later version of VC++ CRT?

    2. Is it possible to make my dll compatible across different versions of CRTs?

    - Hari

    Wednesday, January 27, 2010 7:18 AM

Answers

  • 1. Yes, if you pass STL objects across module boundaries you will most definitely have immediate memory corruption.

    2. No.
    Wednesday, January 27, 2010 7:40 AM
  • N. V. Hari Krishna wrote:
    > Does compiling my dll with /MD flag helps to prevent memory corruption across boundaries?
     
    No. It still won't work if you try to combine modules built with different versions of the compiler (or even the same version, but with different settings). It is a bad idea to use STL classes, or indeed any C++ classes, in the DLL's public interface (with the exception of interfaces - that is, classes with no data members and all functions being pure virtual).
    --
    Igor Tandetnik
    Wednesday, January 27, 2010 1:28 PM

All replies

  • 1. Yes, if you pass STL objects across module boundaries you will most definitely have immediate memory corruption.

    2. No.
    Wednesday, January 27, 2010 7:40 AM
  • Does compiling my dll with /MD flag helps to prevent memory corruption across boundaries?
    Wednesday, January 27, 2010 9:22 AM
  • N. V. Hari Krishna wrote:
    > Does compiling my dll with /MD flag helps to prevent memory corruption across boundaries?
     
    No. It still won't work if you try to combine modules built with different versions of the compiler (or even the same version, but with different settings). It is a bad idea to use STL classes, or indeed any C++ classes, in the DLL's public interface (with the exception of interfaces - that is, classes with no data members and all functions being pure virtual).
    --
    Igor Tandetnik
    Wednesday, January 27, 2010 1:28 PM
  • This is true if DLLs are having different heap if heap is same across dll and process then there should not be issue.
    Wednesday, July 04, 2012 4:47 PM
  • Even then, there can be differences in STL version and differences in compiler flags, causing all sorts of issues.

    It is a bad idea to do this.

    Wednesday, July 04, 2012 7:49 PM
  • In every major version (VS 2005, 2008, 2010, 2012, etc.) we change the representations of STL objects like string and vector, making them binary-incompatible.  We now have linker checks that prevent mixing object files/static libraries compiled with different major versions (2010+), but it's up to you to ensure consistency for DLLs.

    The issue is not "stuff might misbehave, maybe".  It is "stuff will crash, horribly and incomprehensibly".

    Thursday, July 05, 2012 2:01 PM