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


在编译github上面的代码时,遇到了链接错误:

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

Thread.cpp:(.text+0x5f): undefined reference to pthread_atfork' ../Thread.o: In functionmuduo::Thread::~Thread()’:
Thread.cpp:(.text+0x3f9): undefined reference to pthread_detach' ../Thread.o: In functionmuduo::Thread::start()’:
Thread.cpp:(.text+0x50e): undefined reference to pthread_create' ../Thread.o: In functionmuduo::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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM