CMake找不到pthread

克劳迪乌

pthreads在系统上工作:

$ gcc -o what what.c
/tmp/ccI6m52b.o: In function `main':
what.c:(.text+0x37): undefined reference to `pthread_create'
what.c:(.text+0x48): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
$ gcc -pthread -o what what.c
$ ./what
In the thread.

但是,当我cmake使用以下基本知识运行时CMakeLists.txt

cmake_minimum_required(VERSION 2.8.6)
FIND_PACKAGE (Threads)

输出为:

-- Could NOT find Threads (missing:  Threads_FOUND)

是什么赋予了?错误日志状态:

/usr/bin/cc   -std=c11 -D_GNU_SOURCE   -Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Werror -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized -Wlogical-op -Wno-error=maybe-uninitialized -Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes -march=native    -o CMakeFiles/cmTryCompileExec2533162744.dir/CheckIncludeFiles.c.o   -c /mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:5:5: 
     error: function declaration isn’t a prototype [-Werror=strict-prototypes]
 int main(){return 0;}
 ^
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c: 
     In function ‘main’:
/mnt/shared/fooproj/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:5:5: 
     error: old-style function definition [-Werror=old-style-definition]
cc1: all warnings being treated as errors
[...]
Source:
/* */
#include <pthread.h>


int main(){return 0;}
内特·艾德雷奇(Nate Eldredge)

我已经在StackOverflow上回答了这个问题

简短的答案:这是我报告并提供了补丁的CMake错误。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章