简体   繁体   English

克隆使用 vcpkg 的项目时如何安装包

[英]How to install packages when cloning project that uses vcpkg

I am trying out vcpkg package manager but I am running in some issues.我正在试用 vcpkg package 管理器,但遇到了一些问题。 I have a c++ project that uses cmake and vcpkg and have used vcpkg to install the cache2 package. Now everything works but as soon as I push the project and clone it I can't find how to restore the installed packages.我有一个 c++ 项目,它使用 cmake 和 vcpkg,并使用 vcpkg 安装 cache2 package。现在一切正常,但是一旦我推送项目并克隆它,我就找不到如何恢复已安装的包。

What I have done is this:我所做的是:

  • installed vcpkg as submodule安装 vcpkg 作为子模块
  • installed cache2 with vcpkg使用 vcpkg 安装 cache2
  • added cache2 to cmake将 cache2 添加到 cmake

Till here everything works fine now when I push and clone the project it goes wrong.到这里为止一切正常,当我推送和克隆项目出错时。

  • git clone --recurse-submodules git 克隆 --recurse-submodules
  • .\extern\vcpkg\bootstrap-vcpkg.bat .\extern\vcpkg\bootstrap-vcpkg.bat
  • vcpkg list vcpkg列表

Now nothing appears to be installed and I don't want everyone to install all the packages one by one when they clone.现在似乎没有安装任何东西,我不希望每个人在克隆时都一个一个地安装所有的包。 Is there someway to automatically install all packages when cloning?有没有办法在克隆时自动安装所有软件包?

I have found a decent solution using vcpkg manifests, it is still an experimental feature but I haven't had any issues with it yet.我找到了一个使用 vcpkg 清单的不错的解决方案,它仍然是一个实验性功能,但我还没有遇到任何问题。 In order to use manifests do the following:要使用清单,请执行以下操作:

  • At your root folder add a vcpkg.json file with the following contents:在您的根文件夹中添加一个包含以下内容的 vcpkg.json 文件:
{
  "name": "projectname", // should be lowercase, uppercase will give an error
  "version-string": "0.1.0",
  "dependencies": [ // add here your dependencies you would normally install with vcpkg install [package name]
    "catch2"
  ]
}
  • run: vcpkg install --feature-flags=manifests, this will install all dependencies in the array.运行:vcpkg install --feature-flags=manifests,这将安装阵列中的所有依赖项。

In order to remove packages just remove the dependencies from the list and run the above command.为了删除包,只需从列表中删除依赖项并运行上面的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM