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)
posted @ 2020-08-11 10:30  cyssmile  阅读(2843)  评论(0编辑  收藏  举报