4

I'm tryin to use boost threads on mingw (TDM-mingw, 32bit based on gcc4.6) from qtcreator using qmake. I managed to compile boost 1.4.7 using

bjam --toolset=gcc --layout=tagged  --without-mpi --without-python -j 4 stage --build-type=complete

However I simply can not get it to link. I tried to link against several of the libboost_thread libraries created (libboost_thread.a, libboost_thread-mt.a, libboost_thread-mt-dll.a, libboost_thread-mt-s.a), however it always ends up giving me

ld.exe: warning: cannot find entry symbol nable-stdcall-fixup; defaulting to 00401000
main.o:main.cpp:(.text.startup+0x76): undefined reference to `_imp___ZN5boost6thread12start_threadEv'
main.o:main.cpp:(.text.startup+0x89): undefined reference to `_imp___ZN5boost6thread4joinEv'
main.o:main.cpp:(.text.startup+0x9c): undefined reference to `_imp___ZN5boost6threadD1Ev'
main.o:main.cpp:(.text.startup+0xdb): undefined reference to `_imp___ZN5boost6threadD1Ev'

The code I'm trying to compile looks like this:

#include <boost/thread.hpp>
struct thread_main
{ void operator()(){ std::cout<<"Hello World"<<std::endl; } };

int main(int argc, char* argv[])
{
   boost::thread thread((thread_main()));
   thread.join();
   return 0;
}

The compile instructions generated by qmake are as followed:

 g++ -c -std=gnu++0x -fopenmp -march=i686 -mtune=generic -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I'e:/Qt/4.73/Desktop/Qt/4.7.3/mingw/include' -I'e:/Qt/4.73/Desktop/Qt/4.7.3/mingw/include/ActiveQt' -I'release' -I'../Test' -I'.' -I'e:/Qt/4.73/Desktop/Qt/4.7.3/mingw/mkspecs/win32-g++' -o main.o ../Test/main.cpp
 g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-subsystem,console -mthreads -Wl -o Test.exe.exe main.o  -L'e:/boost/stage/lib' -L'e:/Qt/4.73/Desktop/Qt/4.7.3/mingw/lib' -fopenmp -l boost_thread 

According to this it has to be compiled with -DBOOST_THREAD_USE_LIB, however doing so only leads to

ld.exe: warning: cannot find entry symbol nable-stdcall-fixup; defaulting to 00401000
main.o:main.cpp:(.text.startup+0x75): undefined reference to `boost::thread::start_thread()'
main.o:main.cpp:(.text.startup+0x87): undefined reference to `boost::thread::join()'
main.o:main.cpp:(.text.startup+0x99): undefined reference to `boost::thread::~thread()'
main.o:main.cpp:(.text.startup+0xd7): undefined reference to `boost::thread::~thread()'

So how can I convice mingw to link against boost_thread (or if it's a problem with the compile flags given to the linker by qmake, how do I convice it to omit problematic flags?

Community
  • 1
  • 1
Grizzly
  • 19,595
  • 4
  • 60
  • 78
  • Have you tried to link against boost_thread-mt-dll? – David Feurle Nov 05 '11 at 07:23
  • you should also get rid of the `-enable-stdcall-fixup`, at least make it `-Wl,--enable-stdcall-fixup`... – rubenvb Nov 10 '11 at 16:58
  • @rubenvb: Do you know how to do that under qmake? All of -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-subsystem,console -mthreads -Wl seem to have been added somewhere inside of qmake – Grizzly Nov 10 '11 at 17:33
  • 1
    Grizzly: what version of Qt are you using. My qmake.conf (located in `/mkspecs/win32-g++`) doesn't have it (4.8git). If it's there, just add `-Wl,` in front of it (without a space in between). – rubenvb Nov 10 '11 at 17:45

4 Answers4

1

Late answer:

Here's a full description on how to compile boost yourself with MinGW

...and then also how to configure Eclipse to find the headers and libraries. It's not via qtcreator but should work as well.

http://scrupulousabstractions.tumblr.com/post/37052323632/boost-mingw-eclipse

In summary, compile using something like this:

cd F:\coding\boost_1_52_0
.\bootstrap.bat
.\b2 --prefix=F:\coding\some_installation_location toolset=gcc 
       variant=debug,release link=static,shared threading=multi install -j3

(the variant= ... line is meant to be on the same line as .\b2. The option -j3 is just for running 3 jobs in parallel.)

Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97
1

I think you need to list boost_thread before main.o -- the order is important.

Doug Moscrop
  • 4,479
  • 3
  • 26
  • 46
  • No, that doesn't matter. Still gives the same linker errors as the OP describes in the last part of the question ... – πάντα ῥεῖ Nov 04 '12 at 10:55
  • Sorry, forget about my 1st comment order matters! In my particular case ordering of library references not main.o. I had to specify my own libraries using boost_thread before the -lboost_thread option. – πάντα ῥεῖ Nov 04 '12 at 13:24
1

I got a similar error fixed by adding the define line:

#define BOOST_THREAD_USE_LIB

before

#include <boost/thread.hpp>

which apparently makes the linker use the library libboost_thread-mt.a as a static library (as should) and not trying to link it dynamically or such.

as suggested here: Code Blocks, MinGW, Boost, and static linking issues

Community
  • 1
  • 1
Bartel
  • 11
  • 1
0

Just now I recompiled boost once again and now it works, so I assume it was just a case of bjam using the wrong mingw version for some reason

Grizzly
  • 19,595
  • 4
  • 60
  • 78
  • I have the same problem and got at least as far you describe in the question. Do you still know how you did recompiling the boost libs and can you add it here please? – πάντα ῥεῖ Nov 04 '12 at 10:47
  • @g-makulik: Sorry, but not with any certainty. When I did this I had done so much experimenting/tinkering trying to get this to work that I have/had no real clue why it was working all of a sudden. I think it might have been something about the environment/system variables. – Grizzly Nov 05 '12 at 08:51
  • At least it turned out to be a problem of the right ordering of my libs, see my comment on Dougs answer. THX anyway ... – πάντα ῥεῖ Nov 05 '12 at 09:00