我想用boost库1.57在Linux x64上编译我的C++项目。在编译期间关于boost boost静态库的链接错误“undefined reference”
这个项目是用scons编译的,我成功地在我的Arch Linux上编译了它,但是这次在Ubuntu机器上失败了。
我添加了-lboost_coroutine
标志链接,但错误“未定义的参考”仍然存在。
/usr/bin/g++ -o build/gcc.release/app -pthread -g
build/gcc.release/src/han/unity/rpcx.o
-lpthread -lz -lboost_coroutine -lboost_context -lboost_date_time
build/gcc.release/src/han/unity/rpcx.o: In function `attributes':
/usr/local/include/boost/coroutine/attributes.hpp:31: undefined reference
to `boost::coroutines::stack_traits::default_size()'
我注意到attributes.hpp恰恰是boost协程头文件之一。我试图用nm来提升协程库,这似乎没有问题。
nm /usr/local/lib/libboost_coroutine.a | grep "default_size"
0000000000000170 T _ZN5boost10coroutines12stack_traits12default_sizeEv
我搜索了这个错误的可能原因,大部分是关于链接器标志的顺序。在这种情况下,rpcx.o取决于boost_coroutine,所以它出现在前面。
还有什么原因?
尝试在libboost_coroutine之后链接'libboost_thread'。 –
感谢您的评论。我试过但没有工作 – Han
如果你可以通过scons构建它,使用'VERBOSE = 1'包含详细的调试输出,你应该看到用于构建你的应用程序的命令。 –