2

I am trying to build static libraries with the hopes of creating a portable executable. I was successful at building dynamic libraries using the following tutorial:

https://zahidhasan.wordpress.com/2013/02/16/how-to-install-opencv-on-windows-7-64bit-using-mingw-64-and-codeblocks/

I am essentially repeating the process, but with BUILD_SHARED_LIBS = OFF.

I build in CodeBlocks and it fails. The Build messages I get are a series of variations of the following (varying in d00xxxxxx):

C:\TDM-GCC-64\bin..\lib\gcc\x86_64-w64-mingw32\4.9.2\libstdc++.dll.a(d002386.o)|| first defined here|

The Build log shows:

C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2\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:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/libstdc++.dll.a(d002386.o):(.text+0x0): first defined here C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2\libstdc++.a(sstream-inst.o):sstream-inst.cc:(.text$_ZNKSt15basic_stringbufIcSt11char_traitsIcESaIcEE3strEv[_ZNKSt15basic_stringbufIcSt11char_traitsIcESaIcEE3strEv]+0x0): multiple definition ofstd::basic_stringbuf, std::allocator >::str() const' C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/libstdc++.dll.a(d000413.o):(.text+0x0): first defined here

Both of these repeat for the maximum allowed 50 errors.

Any help would be greatly appreciated.

Langleson
  • 103
  • 1
  • 13
  • I would try to see what happens starting from a clean build directory, and activating static library building from the beginning: your problem might be caused by some leftovers of the dynamic library build process. – Antonio Apr 02 '15 at 21:24
  • My apologies if it was unclear. I have done that. I also tried building from the command line with mingw32-make instead of using codeblocks. It looks like it is trying to build compiler libraries as well, specifically 'libstdc++'. Is this normal? – Langleson Apr 02 '15 at 21:28
  • It looks like a compiler/linker bug to me... Where did you download it? – Antonio Apr 02 '15 at 21:40
  • You could try this http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.2/threads-posix/seh/ By the way, are you targetting 32 or 64 architecture? – Antonio Apr 02 '15 at 21:44
  • I can't recall where I downloaded the compiler, I tried a couple until I found one that looked legit. I settled for what appears to be a TDM installer for mingw. I am targeting a 64bit system, but may also want the ability to port to 32 bit. – Langleson Apr 02 '15 at 21:56
  • I suggest you try this other compiler (make sure you do not have any garbage in the path). For targetting 32bit, you have to browse the same site, go up until you get the possibility to choose "Toolchains targeting 32bit" – Antonio Apr 02 '15 at 21:59
  • Well, guys. It looks like I'm just an idiot and I forgot to hit 'Generate' after 'Configure'... twice... Thanks for you help. – Langleson Apr 02 '15 at 22:04
  • The compiler I have has a second folder for called x86_64-w64-ming32. In the bin folder it contains a 'g++.exe' and a x86_64-w64-mingw32-g++.exe (and other equivalents). Am I correct in understanding this can be used to target 32 bit architecture? – Langleson Apr 02 '15 at 22:06
  • Honestly I do not know... – Antonio Apr 02 '15 at 22:08
  • Ok, should it not work, I will follow your advice. Thanks again. – Langleson Apr 02 '15 at 22:21
  • It turns out that I did not forget to hit 'Generate' and the third time I forgot to turn BUILD_SHARED_LIBS off. However, using the proper mingw64 compiler has fixed the issue. – Langleson Apr 03 '15 at 00:56

1 Answers1

0

It looks like a compiler/linker bug to me...

You could try the toolchain available here. (Note: this link might be soon become outdated, so in general use the link below and browse to the most recent version)

And in general at http://sourceforge.net/projects/mingw-w64/files/ where you can also find toolchains targeting 32bit architectures.

Antonio
  • 19,451
  • 13
  • 99
  • 197
  • Thanks. That's exactly what I did and it worked. The TDM version of Mingw64 seems to be defective. I have successfully created the static libraries, now am having issues with undefined references. – Langleson Apr 03 '15 at 19:27