在編譯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,還是有這個問題。
pthread_atfork是POSIX標准,在編譯時要加上-pthread
-lpthread是老版本的gcc編譯器用的,在新版本中應該用-pthread取代-lpthread