cmake
config_error
ai_generated
true
CMake Error: Could not find a configuration file for package "MyPackage" that requests exact version 2.0.0. Found version 2.1.0, but exact match required.
ID: cmake/find-package-version-exact-mismatch
85%Fix Rate
87%Confidence
1Evidence
2023-09-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.18 | active | — | — | — |
| 3.22 | active | — | — | — |
| 3.25 | active | — | — | — |
| 3.28 | active | — | — | — |
Root Cause
find_package is called with EXACT version requirement, but the installed package has a different version (even if minor/patch differ).
generic中文
find_package 使用了 EXACT 版本要求,但已安装的包具有不同的版本(即使只有次要/补丁版本不同)。
Official Documentation
https://cmake.org/cmake/help/latest/command/find_package.html#version-selectionWorkarounds
-
90% success Update the find_package call to accept the installed version: find_package(MyPackage 2.1.0 EXACT) or remove EXACT if not strictly required.
Update the find_package call to accept the installed version: find_package(MyPackage 2.1.0 EXACT) or remove EXACT if not strictly required.
-
85% success Install the exact required version of the package: on Ubuntu, use apt-get install mypackage=2.0.0 or build from source with the correct tag.
Install the exact required version of the package: on Ubuntu, use apt-get install mypackage=2.0.0 or build from source with the correct tag.
-
75% success Use a version range if allowed: find_package(MyPackage 2.0.0...2.1.0 EXACT) is not valid; instead use find_package(MyPackage 2.0.0) without EXACT and add a custom version check.
Use a version range if allowed: find_package(MyPackage 2.0.0...2.1.0 EXACT) is not valid; instead use find_package(MyPackage 2.0.0) without EXACT and add a custom version check.
中文步骤
更新 find_package 调用以接受已安装的版本:find_package(MyPackage 2.1.0 EXACT) 或如果不是严格必要,则移除 EXACT。
安装所需的精确版本包:在 Ubuntu 上,使用 apt-get install mypackage=2.0.0 或从源码构建正确的标签版本。
如果允许,使用版本范围:find_package(MyPackage 2.0.0...2.1.0 EXACT) 无效;改为使用不带 EXACT 的 find_package(MyPackage 2.0.0) 并添加自定义版本检查。
Dead Ends
Common approaches that don't work:
-
Manually editing the package's version file to change the version number
90% fail
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.
-
Using find_package without EXACT but then adding a version check via if()
70% fail
The project may require EXACT for a reason (e.g., ABI compatibility). Removing EXACT can lead to subtle runtime failures.
-
Installing an older version of the package manually from source
85% fail
This can cause conflicts with other system packages that depend on the newer version, leading to dependency hell.