【发布时间】:2021-05-08 08:38:14
【问题描述】:
gcc (GCC) 10.2.0 cmake 版本 3.19.4
CMakeFile.txt
...
test_big_endian(WORDS_BIGENDIAN)
...
cmake 输出:
-- 检查系统是否为大端 -- 搜索 16 位整数 -- 寻找 sys/types.h -- 寻找 sys/types.h - 未找到 -- 寻找 stdint.h -- 寻找 stdint.h - 未找到 -- 寻找 stddef.h -- 寻找 stddef.h - 未找到 -- 检查 unsigned short 的大小 -- 检查 unsigned short 的大小 - 失败 -- 检查 unsigned int 的大小 -- 检查 unsigned int 的大小 - 失败 -- 检查 unsigned long 的大小 -- 检查 unsigned long 的大小 - 在 /usr/local/cmake/share/cmake-3.19/Modules/TestBigEndian.cmake:51 失败的 CMake 错误 (消息):没有找到合适的类型调用堆栈(最近的调用 第一个):contrib/xz/cmake/tuklib_integer.cmake:23 (test_big_endian)
contrib/xz/CMakeLists.txt:126 (tuklib_integer)
CMakeError.log 输出:
确定包含文件 sys/types.h 是否存在失败,输出如下: 更改目录:/data/clickhouse/clickhouse/ClickHouse/build/CMakeFiles/CMakeTmp
运行构建命令:/usr/local/bin/ninja cmTC_73c6f && [1/2] 构建 C 对象 CMakeFiles/cmTC_73c6f.dir/CheckIncludeFile.c.o [2/2] 链接 C 可执行文件 cmTC_73c6f 失败:cmTC_73c6f : && /usr/local/bin/gcc -fdiagnostics-color=always -pipe -msse4.1 -msse4.2 -mpopcnt -Wall -Werror -w -fuse-ld=gold -rdynamic -Wl,--no-undefined -Wl,-no-pie -rdynamic CMakeFiles/cmTC_73c6f.dir/CheckIncludeFile.co -o cmTC_73c6f && : /usr/bin/ld.gold:错误:找不到-lgcc_s /usr/bin/ld.gold:错误:找不到-lgcc_s /lib/../lib64/libc.a(syslog.o):function __vsyslog_chk: error: undefined reference to '_Unwind_Resume' /lib/../lib64/libc.a(syslog.o):function __vsyslog_chk: error: undefined reference to '_Unwind_Resume' /lib/../lib64/libc.a(syslog.o):function openlog: error: undefined reference to '_Unwind_Resume' /lib/../lib64/libc.a(syslog.o):function closelog: error: undefined reference to '_Unwind_Resume' /lib/../lib64/libc.a(syslog.o)(.eh_frame+0xd78b):错误:未定义对“__gcc_personality_v0”的引用 /lib/../lib64/libc.a(backtrace.o):function backtrace_helper: error: undefined reference to '_Unwind_GetIP' /lib/../lib64/libc.a(backtrace.o):function backtrace_helper: error: undefined reference to '_Unwind_GetCFA' /lib/../lib64/libc.a(backtrace.o):function __backtrace: error: undefined reference to '_Unwind_Backtrace' collect2:错误:ld 返回 1 个退出状态 ninja:构建停止:子命令失败。
我找到了错误发生的地方。 cmake-3.19/Modules/CheckIncludeFile.cmake:
if(${VARIABLE})
if(NOT CMAKE_REQUIRED_QUIET)
message(CHECK_PASS "found")
endif()
set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the include file ${INCLUDE} "
"exists passed with the following output:\n"
"${OUTPUT}\n\n")
else()
if(NOT CMAKE_REQUIRED_QUIET)
message(CHECK_FAIL "not found")
endif()
set(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the include file ${INCLUDE} "
"exists failed with the following output:\n"
"${OUTPUT}\n\n")
endif()
错误是什么意思?如何解决?
----新的----
/usr/bin/ld.gold: error: cannot find -lgcc_s 由 gcc 标志 -Wl,-no-pie 引起。为什么找不到gcc_s?
【问题讨论】:
-
我不会太担心大端测试失败。 (一个好的和可移植的实现应该使用 big endian 和 little endian。)我真正关心的是测试失败的原因:
Looking for sys/types.h -- Looking for sys/types.h - not found -- Looking for stdint.h -- Looking for stdint.h - not found -- Looking for stddef.h -- Looking for stddef.h - not found。关于sys/types.h,我不完全确定,但stdint.h和stddef.h?似乎是 C 标准库。找不到标题。 (即使在 C++ 中,也需要 C 标准库。) -
原因是
cmake检查sys/types.h是否存在的方式是通过执行命令/usr/local/bin/gcc -fdiagnostics-color=always -pipe -msse4.1 -msse4.2 -mpopcnt -Wall -Werror -w -fuse-ld=gold -rdynamic -Wl,--no-undefined -Wl,-no-pie -rdynamic CMakeFiles/cmTC_735df.dir/CheckIncludeFile.c.o -o cmTC_735df。但是执行命令时出现了一些错误/usr/bin/ld.gold: error: cannot find -lgcc_s。我发现这个错误是作为参数-Wl,-no-pie发生的。没有这个,命令可以执行成功。