美文网首页C++从入门到放弃
boost多线程undefined reference to s

boost多线程undefined reference to s

作者: lixin_karl | 来源:发表于2019-01-11 10:34 被阅读0次

昨天安装完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
参考

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

相关文章

网友评论

    本文标题:boost多线程undefined reference to s

    本文链接:https://www.haomeiwen.com/subject/utitdqtx.html