解決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