# CMake 错误：找不到请求精确版本 2.0.0 的包 "MyPackage" 的配置文件。找到版本 2.1.0，但需要精确匹配。

- **ID:** `cmake/find-package-version-exact-mismatch`
- **领域:** cmake
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

find_package 使用了 EXACT 版本要求，但已安装的包具有不同的版本（即使只有次要/补丁版本不同）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.18 | active | — | — |
| 3.22 | active | — | — |
| 3.25 | active | — | — |
| 3.28 | active | — | — |

## 解决方案

1. ```
   更新 find_package 调用以接受已安装的版本：find_package(MyPackage 2.1.0 EXACT) 或如果不是严格必要，则移除 EXACT。
   ```
2. ```
   安装所需的精确版本包：在 Ubuntu 上，使用 apt-get install mypackage=2.0.0 或从源码构建正确的标签版本。
   ```
3. ```
   如果允许，使用版本范围：find_package(MyPackage 2.0.0...2.1.0 EXACT) 无效；改为使用不带 EXACT 的 find_package(MyPackage 2.0.0) 并添加自定义版本检查。
   ```

## 无效尝试

- **Manually editing the package's version file to change the version number** — Editing the installed package file is a hack that may break other projects depending on the correct version. It is also overwritten on package updates. (90% 失败率)
- **Using find_package without EXACT but then adding a version check via if()** — The project may require EXACT for a reason (e.g., ABI compatibility). Removing EXACT can lead to subtle runtime failures. (70% 失败率)
- **Installing an older version of the package manually from source** — This can cause conflicts with other system packages that depend on the newer version, leading to dependency hell. (85% 失败率)
