static link fails with "multiple definitions" error
hi there
I am trying to compile opencv 3 statically on windows 7 64 bit using MinGW TDM 64 bit version. I use cmake and i check off the "shared" option before I begin the compilation. During compilation, around 43% progress point, I get the following errors:
Linking CXX executable ..\..\bin\opencv_perf_core.exe c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(sstream-inst.o):sstream-inst.cc:(.text$_ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev[_ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev]+0x0): multiple definition of `std::basic_ostringstream<char, std::char_traits<char="">, std::allocator<char> >::~basic_ostringstream()' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/libstdc++.dll.a(d002421.o):(.text+0x0): first defined here c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(sstream-inst.o):sstream-inst.cc:(.text$_ZNSt19basic_istringstreamIcSt11char_traitsIcESaIcEED1Ev[_ZNSt19basic_istringstreamIcSt11char_traitsIcESaIcEED1Ev]+0x0): multiple definition of `std::basic_istringstream<char, std::char_traits<char="">, std::allocator<char> >::~basic_istringstream()' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/libstdc++.dll.a(d002405.o):(.text+0x0): first defined here c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(sstream-inst.o):sstream-inst.cc:(.text$_ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev[_ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev]+0x0): multiple definition of `std::basic_stringstream<char, std::char_traits<char="">, std::allocator<char> >::~basic_stringstream()' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/libstdc++.dll.a(d002382.o):(.text+0x0): first defined here c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(sstream-inst.o):sstream-inst.cc:(.text$_ZNKSt15basic_stringbufIcSt11char_traitsIcESaIcEE3strEv[_ZNKSt15basic_stringbufIcSt11char_traitsIcESaIcEE3strEv]+0x0): multiple definition of `std::basic_stringbuf<char, std::char_traits<char="">, std::allocator<char> >::str() const' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/libstdc++.dll.a(d000415.o):(.text+0x0): first defined here c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(sstream-inst.o):sstream-inst.cc:(.text$_ZNSt15basic_stringbufIcSt11char_traitsIcESaIcEE7_M_syncEPcyy[_ZNSt15basic_stringbufIcSt11char_traitsIcESaIcEE7_M_syncEPcyy]+0x0): multiple definition of `std::basic_stringbuf<char, std::char_traits<char="">, std::allocator<char> >::_M_sync(char*, unsigned long long, unsigned long long)' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/libstdc++.dll.a(d002216.o):(.text+0x0): first defined here c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(sstream-inst.o):sstream-inst.cc:(.text$_ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode[_ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode]+0x0): multiple definition of `std::basic_ostringstream<char, std::char_traits<char="">, std::allocator<char> >::basic_ostringstream(std::_Ios_Openmode)' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/libstdc++.dll.a(d002417.o):(.text+0x0): first defined here c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(sstream-inst.o):sstream-inst.cc:(.text$_ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode[_ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode]+0x0): multiple definition of `std::basic_stringstream<char, std::char_traits<char="">, std::allocator<char> >::basic_stringstream(std::_Ios_Openmode)' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/libstdc++.dll.a(d002378.o):(.text+0x0): first defined here c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(ios-inst.o):ios-inst.cc:(.text$_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate[_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate]+0x0): multiple definition of `std::basic_ios<char, std::char_traits<char=""> >::clear(std::_Ios_Iostate)' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/libstdc++.dll.a(d002756.o):(.text+0x0): first defined here c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1\libstdc++.a(ios-inst.o):ios-inst.cc:(.text$_ZNSt9basic_iosIcSt11char_traitsIcEE4initEPSt15basic_streambufIcS1_E[_ZNSt9basic_iosIcSt11char_traitsIcEE4initEPSt15basic_streambufIcS1_E]+0x0): multiple definition of `std::basic_ios<char, std::char_traits<char ...
it seems someone has filed a bug report as well: http://code.opencv.org/issues/3759
i tried using -static-libgcc -static-libstdc++ for CMAKE_CXX_FLAGS to no avail
i seem to have fixed it by going through a lot of the "link.txt" files and manually changing all instances of "-lstdc++" with "-static-libstdc++" and it seems to be working. Im sure there is a way to do this from cmake but i did not figure it out.