解决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 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,还是有这个问题。
pthread_atfork是POSIX标准,在编译时要加上-pthread
-lpthread是老版本的gcc编译器用的,在新版本中应该用-pthread取代-lpthread

浙公网安备 33010602011771号