# CMake 错误：版本范围约束 3.20...3.25 未被已安装的 CMake 版本 3.18.4 满足。

- **ID:** `cmake/version-range-constraint-unsatisfied`
- **领域:** cmake
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

项目的 CMakeLists.txt 指定了一个版本范围（例如 cmake_minimum_required(VERSION 3.20...3.25)），要求 CMake >=3.20 且 <4.0，但已安装的 CMake 版本低于下限。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| cmake_minimum_required(VERSION 3.20...3.25) | active | — | — |
| CMake 3.18.4 | active | — | — |
| CMake 3.20.0 | active | — | — |

## 解决方案

1. ```
   从 https://cmake.org/download/ 下载并安装 CMake 3.20 或更高版本。对于 Linux：wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0-linux-x86_64.tar.gz && tar -xzf cmake-3.20.0-linux-x86_64.tar.gz && sudo mv cmake-3.20.0-linux-x86_64 /opt/cmake-3.20 && sudo ln -sf /opt/cmake-3.20/bin/cmake /usr/local/bin/cmake
   ```
2. ```
   使用 pip 安装更新的 CMake：pip install cmake==3.20.0 并确保其在 PATH 中优先。
   ```
3. ```
   修改 CMakeLists.txt 使用单一版本下限：cmake_minimum_required(VERSION 3.18)。仅在确认项目不使用 3.20+ 特性时执行此操作。
   ```

## 无效尝试

- **Set CMAKE_MINIMUM_REQUIRED to a lower version like 3.18** — This bypasses the version check but may break build if project uses features from 3.20+. (70% 失败率)
- **Reinstall CMake from distro package manager (e.g., apt install cmake)** — Distro repositories often have outdated versions; apt may install 3.18 even if you ask for newer. (60% 失败率)
- **Use --version flag to check and then manually symlink to a newer version** — Symlinks don't resolve version constraints; cmake_minimum_required reads the actual binary version. (90% 失败率)
