cmake config_error ai_generated true

CMake Error: Found package version 1.2.3 but required version is 2.0.0 (found /usr/lib/cmake/MyPackage/MyPackageConfig.cmake)

ID: cmake/find-package-config-version-mismatch

Also available as: JSON · Markdown · 中文
90%Fix Rate
92%Confidence
1Evidence
2023-09-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
cmake 3.20.0 active
cmake 3.21.0 active
cmake 3.22.0 active

Root Cause

find_package() found a package configuration file, but its version does not satisfy the version requirements specified in the call.

generic

中文

find_package() 找到了一个包配置文件,但其版本不满足调用中指定的版本要求。

Official Documentation

https://cmake.org/cmake/help/latest/command/find_package.html#version-selection

Workarounds

  1. 90% success Install a newer version of the package that meets the requirement. For example, on Ubuntu: sudo apt-get install mypackage=2.0.0 Or build from source: git clone https://github.com/example/mypackage.git -b v2.0.0 cd mypackage && mkdir build && cd build cmake .. && sudo make install
    Install a newer version of the package that meets the requirement. For example, on Ubuntu:
    
    sudo apt-get install mypackage=2.0.0
    
    Or build from source:
    
    git clone https://github.com/example/mypackage.git -b v2.0.0
    cd mypackage && mkdir build && cd build
    cmake .. && sudo make install
  2. 85% success Specify a lower version requirement in find_package if the API is backward-compatible: find_package(MyPackage 1.2.3 REQUIRED) Or use EXACT to pin to a specific version: find_package(MyPackage 2.0.0 EXACT REQUIRED)
    Specify a lower version requirement in find_package if the API is backward-compatible:
    
    find_package(MyPackage 1.2.3 REQUIRED)
    
    Or use EXACT to pin to a specific version:
    
    find_package(MyPackage 2.0.0 EXACT REQUIRED)

中文步骤

  1. 安装满足要求的较新版本的包。例如,在 Ubuntu 上:
    
    sudo apt-get install mypackage=2.0.0
    
    或从源码构建:
    
    git clone https://github.com/example/mypackage.git -b v2.0.0
    cd mypackage && mkdir build && cd build
    cmake .. && sudo make install
  2. 如果 API 向后兼容,可以在 find_package 中指定较低的版本要求:
    
    find_package(MyPackage 1.2.3 REQUIRED)
    
    或使用 EXACT 固定到特定版本:
    
    find_package(MyPackage 2.0.0 EXACT REQUIRED)

Dead Ends

Common approaches that don't work:

  1. Delete the package config file and let CMake search again 80% fail

    CMake will find the same file again if it's the only one; deleting it may break other projects that depend on it.

  2. Modify MyPackageConfigVersion.cmake to report a higher version 95% fail

    Tampering with version files causes silent runtime errors due to API incompatibility; dangerous and unsupported.