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