CMake由于警告而无法检测到pthread

问题描述:

在使用CMake制作项目时出现错误:

I get an error when making a project with CMake:

-- Could NOT find Threads (missing:  Threads_FOUND)

错误日志显示CMake在真正平凡的事情上跳起来了:

The error log shows that CMake tripped up over something truly banal:

/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;}

这真的应该没有理由CMake认为Threads不存在。

This really should be no reason for CMake to think Threads doesn't exist. How do I go about fixing this?

我相信这是我刚刚报告的CMake bug 15058

CMake用来检查include的测试文件使用旧式C函数定义。如果 -Wold-style-definition -Werror 有效,gcc将对此进行barf。

The test that CMake is using to check the include file uses an old-style C function definition. If -Wold-style-definition -Werror is in effect, gcc will barf on this.

补丁在上面链接的bug报告,但为了快速修复,在您的CMake安装中找到文件 Modules / CheckIncludeFiles.cmake (可能在 / usr / share / cmake 或类似),找到行

I included a patch in the bug report linked above, but for a quick fix, find the file Modules/CheckIncludeFiles.cmake in your CMake installation (possibly in /usr/share/cmake or similar), find the line

  "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")

$ c> int main()到 int main(void)

and change int main() to int main(void).