boost多线程undefined reference to s
2019-01-11 本文已影响0人
lixin_karl
昨天安装完boost后准备使用一下boost,结果在编译的时候遇到这一问题
代码
#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