使用Boost库与mingw

Using Boost libraries with mingw

本文关键字:mingw 库与 Boost 使用      更新时间:2023-10-16

我试图使用qmake从qtcreator在mingw (TDM-mingw,基于gcc4.6的32位)上使用boost线程。我使用

编译了boost 1.4.7
bjam --toolset=gcc --layout=tagged  --without-mpi --without-python -j 4 stage --build-type=complete

然而,我根本无法让它链接。我试图链接几个libboost_thread库创建(libboost_thread.a, libboost_thread-mt.a, libboost_thread-mt-dll.a, libboost_thread-mt-s.a),但它总是最终给我

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'

我试图编译的代码看起来像这样:

#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;
}
qmake生成的编译指令如下:
 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 

根据这个,它必须用-DBOOST_THREAD_USE_LIB编译,但是这样做只会导致

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()'

那么我如何说服mingw链接boost_thread(或者如果它是一个问题与编译标志给链接器由qmake,我如何说服它省略有问题的标志?

我认为你需要在main之前列出boost_thread。O——顺序很重要

我得到了一个类似的错误,通过添加定义行:

#define BOOST_THREAD_USE_LIB

之前
#include <boost/thread.hpp>

使得链接器使用libboost_thread-mt库。A作为一个静态库(这是应该的),而不是试图动态地链接它。

代码块、MinGW、Boost和静态链接问题

迟到的回答:

下面是关于如何使用MinGW编译boost的完整描述

…然后介绍如何配置Eclipse来查找头文件和库。它不是通过qtcreator,但应该也能工作。

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

总而言之,使用如下代码编译:
cd F:codingboost_1_52_0
.bootstrap.bat
.b2 --prefix=F:codingsome_installation_location toolset=gcc 
       variant=debug,release link=static,shared threading=multi install -j3

(变体=…)Line应该与。b2在同一行。选项-j3仅用于并行运行3个作业。)

刚才我再次重新编译boost,现在它工作了,所以我认为这只是一个bjam使用错误的mingw版本的情况下,由于某种原因