gpt4 book ai didi

gcc - 由于警告,CMake 无法检测 pthreads

转载 作者:行者123 更新时间:2023-12-04 02:47:48 24 4
gpt4 key购买 nike

使用 CMake 创建项目时出现错误:

-- Could NOT find Threads (missing:  Threads_FOUND)

错误日志显示 CMake 被一些真正平庸的东西绊倒了:
/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 不存在。我该如何解决这个问题?

最佳答案

我相信这是CMake bug 15058我刚刚报道的。

CMake 用于检查包含文件的测试使用旧式 C 函数定义。如 -Wold-style-definition -Werror实际上,gcc 会对此表示不满。

我在上面链接的错误报告中包含了一个补丁,但要快速修复,请找到文件 Modules/CheckIncludeFiles.cmake在您的 CMake 安装中(可能在 /usr/share/cmake 或类似位置),找到该行

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

并更改 int main()int main(void) .

关于gcc - 由于警告,CMake 无法检测 pthreads,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24813827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com