cmake build_error ai_generated partial

CMake 错误:check_cxx_source_compiles 失败,错误信息为:'error: #error Architecture not supported'

CMake Error: check_cxx_source_compiles failed with: 'error: #error Architecture not supported'

ID: cmake/check-cxx-source-compiles-arch-specific

其他格式: JSON · Markdown 中文 · English
78%修复率
83%置信度
1证据数
2024-06-20首次发现

版本兼容性

版本状态引入弃用备注
CMake 3.27 active
CMake 3.28 active
GCC 12 active
Clang 16 active

根因分析

CMake 的 TryCompile 检查使用的源代码片段包含架构守卫(#ifdef __arm__ 等),在当前目标 CPU 上失败,导致特性检测返回 false 并中止。

English

CMake's TryCompile check uses a source snippet that contains an architecture guard (#ifdef __arm__ etc.) which fails on the current target CPU, causing the feature detection to return false and abort.

generic

解决方案

  1. 通过设置 check_cxx_source_compiles 会定义的变量来覆盖测试,例如在 CMakeCache.txt 中设置 set(HAVE_ARCH_SUPPORT 1) 或通过命令行 -DHAVE_ARCH_SUPPORT=ON。
  2. 修补 CMake 模块文件(例如 /usr/share/cmake-3.28/Modules/FindSomething.cmake),移除架构检查或将你的架构添加到 #ifndef 列表中。

无效尝试

常见但无效的做法:

  1. Set CMAKE_CXX_FLAGS to -march=native or -march=armv8-a 60% 失败

    The error is in the test source itself, not in the flags. Changing march doesn't remove the #error directive.

  2. Delete CMakeCache.txt and reconfigure 50% 失败

    The cache is not the problem; the test source is hardcoded in the Find module or CMake module.