cmake build_error ai_generated partial

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

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

Also available as: JSON · Markdown · 中文
78%Fix Rate
83%Confidence
1Evidence
2024-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
CMake 3.27 active
CMake 3.28 active
GCC 12 active
Clang 16 active

Root Cause

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

中文

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

Workarounds

  1. 70% success Override the test by setting the variable that check_cxx_source_compiles would define, e.g. set(HAVE_ARCH_SUPPORT 1) in CMakeCache.txt or via -DHAVE_ARCH_SUPPORT=ON on command line.
    Override the test by setting the variable that check_cxx_source_compiles would define, e.g. set(HAVE_ARCH_SUPPORT 1) in CMakeCache.txt or via -DHAVE_ARCH_SUPPORT=ON on command line.
  2. 85% success Patch the CMake module file (e.g., /usr/share/cmake-3.28/Modules/FindSomething.cmake) to remove the architecture check or add your arch to the #ifndef list.
    Patch the CMake module file (e.g., /usr/share/cmake-3.28/Modules/FindSomething.cmake) to remove the architecture check or add your arch to the #ifndef list.

中文步骤

  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 列表中。

Dead Ends

Common approaches that don't work:

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

    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% fail

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