您的位置:首页 > Web前端

解决undefined reference to `pthread_atfork'/`pthread_detach'/`pthread_create'/`pthread_join'

2014-10-12 19:39 471 查看
在编译陈硕github上面的代码时,遇到了链接错误:

../Thread.o: In function `(anonymous namespace)::ThreadNameInitializer::ThreadNameInitializer()':

Thread.cpp:(.text+0x5f): undefined reference to `pthread_atfork'

../Thread.o: In function `muduo::Thread::~Thread()':

Thread.cpp:(.text+0x3f9): undefined reference to `pthread_detach'

../Thread.o: In function `muduo::Thread::start()':

Thread.cpp:(.text+0x50e): undefined reference to `pthread_create'

../Thread.o: In function `muduo::Thread::join()':

Thread.cpp:(.text+0x5ce): undefined reference to `pthread_join'

collect2: error: ld returned 1 exit status

在编译时已经加了-lpthread,还是有这个问题。

在这里找到了答案:http://stackoverflow.com/questions/2373109/what-library-to-be-to-be-used-to-avoid-undefined-reference-to-pthread-atfork

pthread_atfork是POSIX标准,在编译时要加上-pthread

-lpthread是老版本的gcc编译器用的,在新版本中应该用-pthread取代-lpthread
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: