C++从入门到放弃

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
参考

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

上一篇 下一篇

猜你喜欢

热点阅读