clion运行下对‘pthread_create’未定义的引用

由于pthread库不是Linux系统默认的库

在CMakeLists.txt的最后加上:

find_package(Threads REQUIRED)
target_link_libraries(项目名称 Threads::Threads)

其中,target_link_libraries的第一个参数 项目名称 为 add_executable(项目名称 ${SOURCE_FILES}) 语句中的项目名

运行就可以编译通过了

猜你喜欢

转载自blog.csdn.net/yyyerica/article/details/70169102