CMake拉取依赖时Protobuf版本不兼容及vcpkg安装报错求助
问题描述
复刻旧程序时,CMake拉取依赖出现Protobuf版本不兼容错误:
Could not find a configuration file for package "Protobuf" that is compatible with requested version "3.1.0".
The following configuration files were considered but not accepted:
E:/GoldbergDevelopment/vcpkg/installed/x64-windows-static/share/protobuf/protobuf-config.cmake, version: 25.1.0
尝试通过vcpkg指定Protobuf版本时,出现Git相关报错:
-- Running vcpkg install error: failed to execute: "C:\Program Files\Git\cmd\git.exe" --git-dir=.git "--work-tree=E:\GoldbergDevelopment\vcpkg\buildtrees\versioning_\versions\protobuf\356bda3330a44573c612a81d53e53994db01fda1_7668.tmp" -c core.autocrlf=false read-tree -m -u 356bda3330a44573c612a81d53e53994db01fda1 error: git failed with exit code: (128). fatal: not a git repository: '.git' note: while checking out port protobuf with git tree 356bda3330a44573c612a81d53e53994db01fda1 error: while checking out baseline from commit 'c7a7d062a750bce13a9db3fa8af5018d38554565', failed to `git show` versions/baseline.json. This may be fixed by fetching commits with `git fetch`. error: git failed with exit code: (128). fatal: not a git repository: '.git' while checking out baseline c7a7d062a750bce13a9db3fa8af5018d38554565 -- Running vcpkg install - failed CMake Error at E:/GoldbergDevelopment/vcpkg/scripts/buildsystems/vcpkg.cmake:902 (message): vcpkg install failed. See logs for more information: E:\GoldbergDevelopment\protobuf_installing\build\vcpkg-manifest-install.log Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.30/Modules/CMakeDetermineSystem.cmake:146 (include) CMakeLists.txt:3 (project) -- Configuring incomplete, errors occurred!
当前使用的vcpkg.json配置:
{ "dependencies": [ "fmt", "protobuf" ], "builtin-baseline": "c7a7d062a750bce13a9db3fa8af5018d38554565", "overrides": [ { "name": "protobuf", "version": "3.2.0" } ] }
解决方案
1. 修复vcpkg的Git仓库问题
报错核心是vcpkg目录无法识别为Git仓库,执行以下操作:
- 进入vcpkg根目录(
E:/GoldbergDevelopment/vcpkg),运行命令:git fetch --all - 如果fetch后仍报错,删除现有vcpkg目录,重新克隆完整仓库:
git clone https://github.com/microsoft/vcpkg.git cd vcpkg .\bootstrap-vcpkg.bat # Windows环境
2. 修正vcpkg.json的版本配置
你需要的是Protobuf 3.1.0,但当前override写的是3.2.0,同时要确保基线版本匹配:
- 打开vcpkg目录下的
versions/p/protobuf.json,找到3.1.0对应的版本条目,确认其version-string和port-version - 修改
vcpkg.json,将override调整为目标版本:{ "dependencies": [ "fmt", "protobuf" ], "builtin-baseline": "c7a7d062a750bce13a9db3fa8af5018d38554565", "overrides": [ { "name": "protobuf", "version-string": "3.1.0", "port-version": 0 # 对应protobuf.json中3.1.0的port-version值 } ] } - 确保
builtin-baseline的commit存在于本地vcpkg仓库,若不存在,先执行git fetch拉取该commit
3. 清理缓存与重建
- 删除vcpkg的protobuf构建缓存:
rm -rf E:/GoldbergDevelopment/vcpkg/buildtrees/protobuf - 删除已安装的高版本Protobuf:
rm -rf E:/GoldbergDevelopment/vcpkg/installed/x64-windows-static/protobuf - 删除项目的build目录,重新运行CMake配置命令
4. 备选方案:手动指定版本安装
如果manifest方式仍有问题,直接用vcpkg命令行安装指定版本:
vcpkg install protobuf[core]:x64-windows-static@3.1.0
安装完成后,在CMake中指定该版本的Protobuf路径即可。
内容的提问来源于stack exchange,提问作者Mubinul Haque
相关产品推荐
相关产品推荐

