【发布时间】:2021-10-17 05:31:16
【问题描述】:
我正在尝试使用 boost 库 1.57 在 Linux x64 上编译我的 C++ 项目。
这个项目是用 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。 -
感谢您的评论。我试过但没有用
-
如果您可以通过 scons 构建它,请使用
VERBOSE=1包含详细的调试输出,您应该会看到用于构建您的应用程序的命令。
标签: c++ linux boost linker undefined-reference