undefined reference to `pthread_create‘(linux下Clion使用thread报错)
生活随笔
收集整理的這篇文章主要介紹了
undefined reference to `pthread_create‘(linux下Clion使用thread报错)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
完整報錯:
====================[ Build | AsyncLogger | Debug ]============================= /snap/clion/169/bin/cmake/linux/bin/cmake --build /home/dyy/CLionProjects/AsyncLogger/cmake-build-debug --target AsyncLogger -- -j 6 [ 50%] Linking CXX executable AsyncLogger /usr/bin/ld: CMakeFiles/AsyncLogger.dir/main.cpp.o: in function `std::thread::thread<void (&)(), , void>(void (&)())': /usr/include/c++/9/thread:126: undefined reference to `pthread_create' collect2: error: ld returned 1 exit status make[3]: *** [CMakeFiles/AsyncLogger.dir/build.make:93:AsyncLogger] 錯誤 1 make[2]: *** [CMakeFiles/Makefile2:83:CMakeFiles/AsyncLogger.dir/all] 錯誤 2 make[1]: *** [CMakeFiles/Makefile2:90:CMakeFiles/AsyncLogger.dir/rule] 錯誤 2 make: *** [Makefile:124:AsyncLogger] 錯誤 2解決方法:
在CMakeLists.txt的最后加上:
然后reload CMakeLists.txt,編譯成功。
原因:
編譯器沒有鏈接線程庫
總結
以上是生活随笔為你收集整理的undefined reference to `pthread_create‘(linux下Clion使用thread报错)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DNF买段交易方式
- 下一篇: “岂念慕羣客”上一句是什么