由于警告,CMake 无法检测 pthread [英] CMake failing to detect pthreads due to warnings
问题描述
使用 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 我刚刚报道的.
I believe this is CMake bug 15058 which I just reported.
CMake 用于检查包含文件的测试使用旧式 C 函数定义.如果 -Wold-style-definition -Werror
生效,gcc 会对此感到厌烦.
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.
我在上面链接的错误报告中包含了一个补丁,但要快速修复,请在您的 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}
int main(){return 0;}
")
并将int main()
改为int main(void)
.
这篇关于由于警告,CMake 无法检测 pthread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!