boost多线程undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'

昨天安装完boost后准备使用一下boost,结果在编译的时候遇到这一问题

代码
#include 
#include 
#include 
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
参考

https://blog.csdn.net/u011641865/article/details/73498533

你可能感兴趣的:(boost多线程undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5')