我跟着get started构建并安装boost 1.61.0
到mypath-to-boost
,然后尝试使用下面的libboost_thread
,
// mythread.cpp
#include <boost/thread.hpp>
void a_thread() {}
int main() {
boost::thread t{a_thread};
}
建立mythread.cpp
,
$ g++ mythread.cpp -std=c++11 -Imypath-to-boost -lboost_thread -Lmypath-to-boost/lib
然后出错了,
/usr/bin/ld: warning: libboost_system.so.1.61.0, needed by mypath-to-boost/lib/libboost_thread.so, not found (try using -rpath or -rpath-link)
mythread.cpp: undefined reference to `boost::system::generic_category()'
...
检查libboost_thread
,
$ ls -l mypath-to-boost/lib/*thread*
然后找到了libs,
libboost_thread.a
libboost_thread.so -> libboost_thread.so.1.61.0
libboost_thread.so.1.61.0
那么造成构建失败的问题是什么?
答案 0 :(得分:1)
您需要将boost_system
库添加到链接行...