Using Boost libraries with mingw

I am trying to use boost streams in mingw (TDM-mingw, 32 bit 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 just can't tie it up. I tried linking several libboost_thread libraries created ( libboost_thread.a, libboost_thread-mt.a, libboost_thread-mt-dll.a, libboost_thread-mt-sa ), but that 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 is as follows:

 #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 compilation commands created by qmake are as follows:

  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 -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  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 

Accordingly , it should be compiled with -DBOOST_THREAD_USE_LIB , however this 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 convection mingw to reference boost_thread (or if this is a problem with the compilation flags provided to the qmake linker, how can I convince it to omit the problematic flags?

+4
source share
4 answers

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

0
source

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

+1
source

I got a similar error fixed by adding a definition line:

 #define BOOST_THREAD_USE_LIB 

front

 #include <boost/thread.hpp> 

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

as suggested here: Code blocks, problems with MinGW, Boost, and static links

+1
source

Late answer:

Here's a complete description of how to compile with MinGW

... and then also configure Eclipse to search for headers and libraries. It is not through qtcreator, but should work.

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

In general, 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 

(line variant = ... should be on the same line as. \ b2. The -j3 parameter is designed to run 3 jobs at the same time.)

+1
source

All Articles