使用Boost库与mingw
Using Boost libraries with mingw
我试图使用qmake从qtcreator在mingw (TDM-mingw,基于gcc4.6的32位)上使用boost线程。我使用
编译了boost 1.4.7bjam --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版本的情况下,由于某种原因
相关文章:
- 无法将 GLFW 库与 Ubuntu 18.04 上的头文件链接
- 无法在Ubuntu上将共享库与Eclipse链接
- 为什么构建目录中新构建的共享库与安装目录中的副本具有不同的依赖项集?
- 使用静态库与 std::jthread (g++-10) 的分段错误
- 不能将C++的"std::filesystem"库与介子构建一起使用
- 如果包含映射的静态库与可执行文件和动态库链接,静态映射(变量)是否会被多次释放?
- 将预编译的 C 共享库与 JNI/NDK 结合使用
- 如何将 PhysX 库与 Xcode 链接
- NDK 将库与 cmake 链接
- 无法将提升库与 CMake 链接
- 强制链接静态库与 cmake 不起作用
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 如何在应用程序子项目中将静态库与gradle子项目链接起来
- 如何将动态链接库与CMake一起使用
- 如何将英特尔的数学函数库与 gcc 一起使用?
- 将外部C++库与 CMake 一起使用时出错
- SWIG和Mingw-64与Python一起使用...不是有效的 Win32 应用程序
- Boost(1.50.0)线程库与MinGW的链接
- 使用Boost库与mingw
- mingw g++无法与库链接