CMake時報undefined reference to `pthread_create'錯誤


今天自己用CMake搭建一個項目時,其中用到了多線程
在make的時候報了 undefined reference to `pthread_create'這個錯誤,網上很多都是說lpthread 不是linux下默認的庫之類的。
只需要在編譯的時候加上-lpthread參數。雖然可以解決問題,但是這個並不是我想要的答案,我想要知道CMake中怎么修改。
這里使用的頭文件是

#include <thread>

解決方法

在CMakeLists.txt中鏈接目標程序的程序時加上pthread庫就好了。

target_link_libraries(main pthread)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM