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

- **ID:** `cmake/check-ipos-supported-false`
- **领域:** cmake
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| cmake 3.21.0 | active | — | — |
| cmake 3.22.0 | active | — | — |
| cmake 3.23.0 | active | — | — |

## 解决方案

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
   ```

## 无效尝试

- **Set CMAKE_INTERPROCEDURAL_OPTIMIZATION to TRUE manually** — Overrides the check but may cause linker errors if the toolchain genuinely lacks LTO support; build will fail later. (70% 失败率)
- **Upgrade CMake to the latest version** — LTO support depends on the compiler, not CMake version; upgrading CMake does not add LTO to an unsupported compiler. (90% 失败率)
