cmake config_error ai_generated partial

CMake 错误:check_ipo_supported() 失败 - 编译器/工具链不支持 LTO

CMake Error: check_ipo_supported() failed - LTO not supported by compiler / toolchain

ID: cmake/check-ipos-supported-false

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
1证据数
2024-05-08首次发现

版本兼容性

版本状态引入弃用备注
cmake 3.21.0 active
cmake 3.22.0 active
cmake 3.23.0 active

根因分析

编译器或链接器不支持当前构建配置的链接时优化 (LTO),或者 check_ipo_supported() 调用检测到不兼容。

English

The compiler or linker does not support Link-Time Optimization (LTO) for the current build configuration, or the check_ipo_supported() call detected incompatibility.

generic

官方文档

https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html

解决方案

  1. 通过显式设置属性来禁用受影响目标的 LTO:
    
    set_target_properties(mytarget PROPERTIES INTERPROCEDURAL_OPTIMIZATION FALSE)
    
    或全局设置:
    
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
  2. 使用支持 LTO 的编译器(例如 GCC 4.9+ 或 Clang 3.9+)。对于 GCC,确保 'gold' 链接器可用:
    
    sudo apt-get install binutils-gold
    
    然后使用以下命令重新配置:
    
    cmake -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=TRUE -DCMAKE_LINKER=/usr/bin/ld.gold /path/to/source

无效尝试

常见但无效的做法:

  1. Set CMAKE_INTERPROCEDURAL_OPTIMIZATION to TRUE manually 70% 失败

    Overrides the check but may cause linker errors if the toolchain genuinely lacks LTO support; build will fail later.

  2. Upgrade CMake to the latest version 90% 失败

    LTO support depends on the compiler, not CMake version; upgrading CMake does not add LTO to an unsupported compiler.