1. 程式人生 > >boost 程式編譯錯誤

boost 程式編譯錯誤

1、環境:

ubuntu18.04 桌面版

2、boost_1_67_0.tar.bz2 程式包編譯後安裝(具體過程百度下非常容易實現)

3、測試程式碼

#include <boost/thread.hpp> #include <iostream> void task1(){         std::cout<<"this is task1!"<<std::endl; } void task2(){         std::cout<<"this is task2!"<<std::endl; } int main(int argc,char **argv){         using namespace boost;         thread thread_1=thread(task1);         thread thread_2=thread(task2);         boost::this_thread::sleep(boost::posix_time::seconds(2));         thread_2.join();         thread_1.join();         return 0;

}

編譯指令:

g++ t1.cpp -I /usr/local/include/ -L /usr/local/lib/   -lboost_system -lboost_filesystem -lboost_thread -o t1

錯誤提示:

usr/bin/ld: /tmp/cccCDjBu.o: undefined reference to symbol '[email protected]@GLIBC_2.3.3' //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status

修正後的編譯指令:g++ t1.cpp -I /usr/local/include/ -L /usr/local/lib/   -lboost_system -lboost_filesystem -lboost_thread -lpthread  -o t1

說明:

   增加了 -lpthread 問題解決

   ld找不到對應symbol不是由於對應so不在路徑中,而是DSO missing from command line.連結階段,指定使用的動態庫:-lpthread