昨天安裝完boost后準(zhǔn)備使用一下boost,結(jié)果在編譯的時(shí)候遇到這一問題
代碼
#include <boost/thread/thread.hpp>
#include <iostream>
#include <unistd.h>
using namespace std;
void func1()
{
cout << "func1"<< endl;
sleep(1);
}
void func2()
{
cout << "func2:"<< endl;
sleep(2);
}
int main()
{
boost::thread thread1(&func1);
boost::thread thread2(&func2);
sleep(5);
isRuning = false;
thread2.join();
thread1.join();
return 0;
}
編譯語句
g++ -std=c++11 main.cpp -lboost_thread
問題
/usr/bin/ld: /tmp/ccgsMvZP.o: undefined reference to symbol 'pthread_condattr_setclock@@GLIBC_2.3.3'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
解決辦法
加上-pthread
g++ -std=c++11 main.cpp -lboost_thread -lpthread