使用vcpkg与find_package()时CMake报错“配置文件未被接受”
解决frugally-deep在CMake中find_package兼容性问题
问题场景
已通过vcpkg install frugally-deep eigen3 nlohmann-json functionalplus安装了相关库,CMakeLists.txt配置如下:
cmake_minimum_required(VERSION 3.22) project(untitled) set(CMAKE_CXX_STANDARD 17) find_package(Eigen3 CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED) find_package(FunctionalPlus CONFIG REQUIRED) find_package(frugally-deep CONFIG REQUIRED) add_executable(untitled main.cpp)
手动指定各包路径参数后,Eigen3、nlohmann_json、FunctionalPlus均可正常找到,但frugally-deep报以下错误:
CMake Error at CMakeLists.txt:9 (find_package):
Could not find a configuration file for package "frugally-deep" that is
compatible with requested version "".The following configuration files were considered but not accepted:
C:/vcpkg/packages/frugally-deep_x86-windows/share/frugally-deep/frugally-deepConfig.cmake, version: 0.15.19 (32bit)
解决方法
1. 统一目标架构(核心解决)
错误提示明确标注frugally-deep是32bit版本,与当前CMake项目的编译架构不匹配:
- 若需要64位编译,重新安装对应架构的库:
vcpkg install frugally-deep:x64-windows eigen3:x64-windows nlohmann-json:x64-windows functionalplus:x64-windows - 若坚持使用32位,在CMake配置时添加架构参数:
-A Win32。
2. 使用vcpkg自动集成(推荐)
无需手动指定每个包的_DIR参数,改用vcpkg的toolchain文件自动管理依赖路径:
在CMake配置时添加参数:
-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake
vcpkg会自动匹配对应架构的库,避免手动路径指定的错误。
3. 显式指定版本(辅助验证)
如果确认架构匹配,可在find_package中显式指定版本号,确保版本兼容:
find_package(frugally-deep CONFIG REQUIRED 0.15.19)
内容的提问来源于stack exchange,提问作者david-palm
相关产品推荐
相关产品推荐

