Menu

#1656 Unloading a C++ DLL crashes since GCC 4.5

OTHER
closed
nobody
gcc (462)
wont-fix
component_package
2013-01-23
2012-07-10
No

Since GCC 4.5, I get crashes on FreeLibrary() freeing a DLL making use of C++ std::string.
The problem only happens when invoking the linker by 'gcc' rather than 'g++'.
However, both executable and shared library are built by explicitly linking: -lstdc++

The following error message will show to a console or popup box right after the FreeLibrary() call:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Very easy to reproduce:

DLL code:
-------------------------
#include <string>
void Test()
{
std::string("hello");
}
--------------------------
gcc -g -Wall -D_DEBUG -c cppTest.cpp -o obj/debug.win32/cppTest.o
gcc obj/debug.win32/cppTest.o -shared -lstdc++ -o obj/debug.win32/cppTest.dll
(If using g++ instead of gcc here, no problem)

Test app code:
-------------------------
#include <windows.h>

int main()
{
HMODULE l = LoadLibrary("cppTest");
FreeLibrary(l);
return 0;
}
-------------------------
gcc -g -Wall -D_DEBUG -c cppTestClient.cpp -o obj/debug.win32/cppTestClient.o
gcc obj/debug.win32/cppTestClient.o -mwindows -lstdc++ -o obj/debug.win32/cppTestClient.exe

Thanks,

Jerome

Discussion

  • Earnie Boyd

    Earnie Boyd - 2012-07-10
    • status: open --> closed-wont-fix
     
  • Earnie Boyd

    Earnie Boyd - 2012-07-10

    All I can say is that you're supposed to be using G++ instead of GCC for C++ compilation. If you believe this is truly an issue then take it up with the bugs list for GCC.

     
  • Jerome St-Louis

    Jerome St-Louis - 2012-07-10

    Turns out that adding -shared-libgcc to the gcc linker line works fine.
    (Thanks to apinski on #gcc)

    Arguably, this should be default when linking with -lstdc++ dynamically.
    Taking it up with them. Thanks Earnie.

     
  • Earnie Boyd

    Earnie Boyd - 2013-01-23
    • status: closed-wont-fix --> closed
    • resolution: --> wont-fix
    • category: --> component_package
    • milestone: --> OTHER