Subject: bug#8503: Multiple definition errors when statically linking libstdc++

From: Nathan Sharp <[email-masked]>
Date: Thu, 14 Apr 2011 20:22:19 -0400 (EDT)

Libtool is adding on libstdc++.dll.a, even when -static-libstdc++ option is specified.

We are building a DLL on Windows XP using MinGW.  Due to what appears to be a performance bug in MinGW, we'd like to statically link libstdc++.  Attempting to use CXXFLAGS="-static-libstdc++" seems to get very close to working, but libtool tries to link on libstdc++.dll.a even with this flag set and we end up getting errors such as:

C:/MinGW/lib/gcc/mingw32/4.5.2\libstdc++.a(sstream-inst.o):(.text$_ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev[std::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()]+0x0): multiple definition of `std::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()'
C:/MinGW/lib/gcc/mingw32/4.5.2/libstdc++.dll.a(d002250.o):(.text+0x0): first defined here

I found that passing -all-static to libtool fixes the problem.  However, -all-static is not a valid g++ option, and I can't figure out how to pass an option just to libtool and not to g++ from configure.  I'm currently working around this (incorrectly) by adding the option to Makefile.am under progname_LDFLAGS.

Why shouldn't libtool drop libstdc++.dll.a from the arguments to the linker when -static-libstdc++ is present, though?  

libtool 2.4
g++ 4.5.2

Thanks!
  Nathan

------------------------------------------------ 
Nathan Sharp 
Phoenix Integration Inc 
www.phoenix-int.com