• 乘风破浪,遇见最美Windows 11之现代Windows桌面应用开发 跨平台C/C++依赖包管理工具Vcpkg,微软出品必属精品,让你爽爆


    什么是Vcpkg

    https://vcpkg.io

    https://github.com/microsoft/vcpkg

    image

    来自微软的C/C++依赖性管理器,适用于所有平台、构建系统和工作流程

    Vcpkg是微软的一个跨平台开源软件包管理器。

    Vcpkg是一个免费的C/C++软件包管理器,用于获取和管理库。从1500多个开源库中选择下载并在一个步骤中构建,或者添加你自己的私有库来简化你的构建过程。由微软C++团队和开放源码贡献者维护

    简单性和灵活性是vcpkg的核心

    • 易于使用

    image

    只需一个步骤就可以下载和构建流行的库。不用担心上游的依赖性或版本冲突。通过命令行操作或在清单中声明依赖关系,可以与你的repo一起使用。获得开发团队、文档和活跃社区的支持。

    • 通用性

    image

    vcpkg可以与你喜欢的操作系统、构建系统、目标架构、IDE、编辑器和持续集成过程一起工作。库是由源码构建的,可以配置。

    • 可靠的

    image

    保持本地开发者和CI/CD工作流程之间的一致性。保持在你喜欢的库版本上。与你的团队其他成员同步你的依赖性生态系统。

    • 面向所有人

    image

    无论你是一个小型开源项目的单人团队,还是一个有复杂构建和安全需求的大型企业,都可以利用最新的vcpkg功能来实现你的工作流程。缓存二进制文件以加快消耗,避免钻石依赖性解决的问题,为所有开发人员、CI机器和容器复制相同的构建。带来你自己的库或消费流行的公共库。利用现有的Visual Studio和Visual Studio Code集成的优势。

    优点

    • 自动下载开源库源代码
    • 源码包的缓存管理和版本管理,可以升级版本
    • 轻松编译
    • 依赖关系检查(比如编译libcurl,会自动下载zlib、openssl进行编译)
    • 无缝集成Visual Studio,不需要设置库文件、头文件的所在目录,自动集成。
    • Visual Studio全平台支持,不仅支持Debug/Release、x86/x64编译,还支持UWP、ARM平台的编译

    历史由来

    https://github.com/CppCon/CppCon2016

    vcpkg为其支持的平台提供对C和C++库的访问。该命令行工具目前可用于Windows、macOS和Linux。

    vcpkg在CppCon 2016上首次发布

    vcpkg的源代码在MIT许可下授权,并托管在GitHub上。

    vcpkg支持Visual Studio 2015 Update 3及以上版本。

    2016年9月19日,Vcpkg:一个在Windows上获取和构建C++开放源代码库的工具

    https://devblogs.microsoft.com/cppblog/vcpkg-a-tool-to-acquire-and-build-c-open-source-libraries-on-windows/

    我们很高兴地宣布Vcpkg在GitHub上的可用性https://github.com/Microsoft/vcpkg。 Vcpkg简化了Windows上开源库的获取和构建

    在Windows上获取本地库是应用程序开发过程中的一个关键部分;在我们的调查中,你告诉我们80%的C++项目都依赖于两个或多个库。尽管如此,我们听说,与其他平台如Mac(Homebrew)和Linux(apt-get、yum等)相比,目前获取本地库的过程低于C++开发者的期望

    在研究了所有平台的成功经验后,我们以这套原则创建了Vcpkg:

    • 开源工具
    • 不需要安装
    • 可重复的构建,从源头开始
    • 可定制的构建
    • 对社区的贡献开放
    • 端口收集方法

    我们创建了一份文件,对这些主题进行了更详细的说明。

    入门

    先决条件:

    • Visual Studio 2015或Visual Studio 2017(在Windows上)。
    • Windows 7(或以上)
    • Linux或MacOS(vcpkg现在是跨平台的,见公告)

    要获得该工具:

    • 从GitHub克隆:git clone https://github.com/Microsoft/vcpkg
    • 运行vcpkg文件夹中的引导脚本。
    • C:\src\vcpkg> .\bootstrap-vcpkg.bat
    • Ubuntu:~/$ ./bootstrap-vcpkg.sh
    • 现在vcpkg.exe在版本库的根目录下了。

    你现在都准备好了(无需安装,无需注册......该工具和相关的 "lib文件夹 "是可以复制的)

    可用的三段式

    • arm-uwp.cmake
    • arm-windows.cmake
    • arm64-uwp.cmake
    • arm64-windows.cmake
    • x64-linux.cmake
    • x64-osx.cmake
    • x64-uwp.cmake
    • x64-windows-static.cmake
    • x64-windows.cmake
    • x86-uwp.cmake
    • x86-windows-static.cmake
    • x86-windows.cmake

    库列表 (08/17/2018)

    要查看759个库(1054个可用包)的列表,请使用vcpkg search

    包名称 版本号 包描述
    3fd 2.6.2 C++ Framework For Fast Development
    abseil 7/30/2018 an open-source collection designed to augment the C++ standard library. Abseil…
    ace 6.5.1 The ADAPTIVE Communication Environment
    alac 2017-11-03-c3… The Apple Lossless Audio Codec (ALAC) is a lossless audio codec developed by A…
    alac-decoder 0.2 ALAC C implementation of a decoder written from reverse engineering the file …
    alembic 1.7.8 Alembic is an open framework for storing and sharing scene data that includes …

    ...

    我们接受对新库、更新和改进的贡献。请看如何在目录中创建你自己的端口文件的例子

    在你的项目中使用Vcpkg

    从Visual Studio使用Vcpkg最简单的方法是通过用户范围的集成,使该系统对你建立的所有VS项目可用

    vcpkg integrate install
    

    第一次在指定的机器上使用时,这需要管理员权限。在第一次使用后,不再需要管理员访问,集成是以每个用户为基础的。

    除了VS集成之外,Vcpkg还支持CMake和其他构建系统。更多信息,请参见docs/EXAMPLES

    我们想听听你的意见!

    这个工具现在可以供你试用。请分享您的反馈和建议! 提供这些建议的最佳地点是GitHub repo:创建新问题或对现有问题进行投票。我们很愿意接受更多开源库的拉取请求--见docs/index.md。

    你也可以通过vcpkg@microsoft.com联系我们。

    2018年4月24日,宣布为Linux、macOS和Windows提供一个单一的C++库管理器:Vcpkg

    https://devblogs.microsoft.com/cppblog/announcing-a-single-c-library-manager-for-linux-macos-and-windows-vcpkg/

    在微软,我们愿景的核心是"任何开发者,任何应用程序,任何平台",我们致力于为您提供最富有成效的开发工具和服务,以便在所有平台上构建您的应用程序。考虑到这一点,我们今天很高兴地宣布vcpkg在Linux和MacOS上的可用性。这让你可以在两个新的平台上立即访问vcpkg的C++库目录,其步骤与你今天在Windows和UWP上熟悉的一样。

    自从在CppCon 2016上推出以来,Vcpkg已经取得了长足的进步。从只有20个库开始,在过去的19个月里,我们看到了令人难以置信的增长,现在有超过900个库和功能可用。所有的功劳都归功于我们惊人的社区的宝贵贡献

    在你到目前为止给我们的反馈中,Linux和Mac支持是迄今为止要求最多的功能。因此,我们今天很高兴看到vcpkg进入了一个更广泛的社区,并促进了对更多C++库的跨平台访问。我们今天邀请您尝试一下vcpkg,无论您的目标是Windows、Linux还是MacOS

    要了解更多关于在Windows上使用vcpkg的信息,请阅读我们之前关于如何在Windows上开始使用vcpkg的文章

    在Linux和Mac上使用vcpkg

    Vcpkg工具现在与Linux、Mac和其他POSIX系统兼容。这完全是通过几个出色的社区成员的贡献而实现的

    在写这篇博文的时候,有超过350个库可以在Linux和Mac上使用,我们希望这个数字能迅速增长。目前,我们每天在Ubuntu-LTS 16.04/18.04上进行测试,我们在Arch、Fedora、FreeBSD上也取得了成功

    开始吧

    1. 克隆vcpkg repo: git clone https://github.com/Microsoft/vcpkg

    2. 启动vcpkg:``./bootstrap-vcpkg.sh`

    3. 一旦vcpkg建立起来,你就可以使用以下语法建立任何库。

    vcpkg install sdl2
    

    这将安装sdl2:x64-linux(x64 static是默认的,也是Linux上唯一可用的选项)

    结果(.h, .lib)存储在同一个文件夹树中,在你的构建系统配置中引用这个文件夹。

    1. 使用生成的库

    如果你使用CMake作为构建系统,那么你应该使用CMAKE_TOOLCHAIN_FILE来使库可以用find_package()。例如:cmake ... "-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"

    你应该引用包含头文件的vcpkg文件夹(\vcpkg\installed\x64-linux\include)和包含.lib的文件夹(\vcpkg\installed\x64-linux\lib),以便能够使用生成的库构建你的项目。

    image

    image

    使用vcpkg通过WSL从Windows瞄准Linux

    由于WSL是一个Linux系统,我们将像使用Linux那样使用WSL。一旦配置正确,你就可以从你的Windows机器上生成Linux二进制文件,就像它们是从Linux盒子上生成的一样。按照在Linux上安装时的相同说明进行操作。请看如何在Windows 10上设置WSL,并将其]与Visual Studio扩展一起配置为Linux

    image

    如上面的截图所示,vcpkg目录可以在Windows和WSL之间共享。在这个例子中,sdl2和sqlite3是由WSL构建的(Linux的二进制文件);sqlite3也是为Windows构建的(Windows dll)。

    最后

    在Linux或Mac上安装vcpkg,并在你的跨平台项目中试用它,让我们知道我们怎样才能使它变得更好,以及你的跨平台使用情况是什么

    像往常一样,你的反馈和意见对我们来说真的很重要,如果有任何意见和建议,请在GitHub上开一个问题,或者联系我们:vcpkg@microsoft.com。请花点时间完成我们的调查。

    2021年12月6日,用vcpkg工件启动你的开发环境

    https://devblogs.microsoft.com/cppblog/vcpkg-artifacts/

    我们很高兴地宣布使用vcpkg获取工件的新体验。我们将人工制品定义为工作开发环境所需的一组软件包。相关软件包的例子包括编译器、链接器、调试器、构建系统和平台SDKs。有了这个重要的变化,vcpkg不仅可以从源头下载和构建你的库,它还可以引导你环境的其他部分,为你的项目获得预构建的二进制依赖。

    该体验处于预览阶段,目前主要针对嵌入式开发者。我们将在未来扩大范围,包括任何针对Linux、macOS或Windows的开发者。

    这篇文章的重点是在命令行中使用vcpkg工件。请查看Visual Studio中的嵌入式开发博文,了解如何在那里使用这些功能。

    在这里,我们将展示如何获取vcpkg,然后激活工件来构建一个嵌入式项目。之后我们将介绍用于查找和使用工件的特定vcpkg功能,然后是如何创建清单并向其中添加工件。我们还将介绍如何使用不属于默认神器注册表的自己的神器。

    使用vcpkg工件

    我们将看看一些嵌入式开发场景,以了解vcpkg中新的工件功能。嵌入式开发尤其以难以让一个新的开发者机器开始工作而闻名。项目往往有特定的编译器要求,需要特殊的调试工具,等等。我们将在这里展示的是,通过使用vcpkg与清单,你可以捕捉到这些需求,并轻松地为一个嵌入式项目恢复环境。你不需要一个设备来跟随,因为我们不会显示任何设备的交互性。这些步骤除注明外都是跨平台的。

    获取vcpkg

    我们还增加了一个新的方法,可以在单一步骤中获得vcpkg,而不需要git克隆 repo。根据你的平台,使用以下命令之一来获取vcpkg。

    • Linux/macOS
    . <(curl https://aka.ms/vcpkg-init.sh -L)
    
    • PowerShell
    iex (iwr -useb https://aka.ms/vcpkg-init.ps1)
    
    • CMD Shell
    curl -LO https://aka.ms/vcpkg-init.cmd && .\vcpkg-init.cmd
    

    克隆示例项目

    例子项目是Azure RTOS的入门版本,所以先用这个命令克隆它。

    git clone --recursive https://github.com/azure-rtos/getting-started.git
    

    这个Repo里有很多项目,每个项目都是针对一个特定的板子。通过切换到该目录来使用Azure IoT DevKit。

    cd .\getting-started\MXChip\AZ3166\
    

    激活vcpkg

    在项目文件夹中,有一个文件vcpkg-configuration.json。这个清单文件记录了你构建和调试这个项目所需的工具。运行vcpkg activate命令将使用这个文件来确定这些工具是否曾经被获取过,如果没有被获取,就在你的环境中激活它们,以供使用。

    vcpkg activate
    

    这是一个新的vcpkg命令,它与工件一起工作。由于这是你第一次使用vcpkg处理工件,所以它按要求获取了新的vcpkg-ce组件。这个组件名称中的ce代表configure environment。选择这个名字是因为vcpkg将修改你当前的环境,以便在你的C++项目中使用清单中的工件。

    cmake --preset arm-gcc-cortex-m4
    cmake --build --preset arm-gcc-cortex-m4
    

    为了证明这一点,请构建该项目。为此要生成CMake配置,然后使用项目中CMakePresets.json提供的预设,用以下两个命令构建项目。

    寻找工件

    已经有一个vcpkg搜索命令可以在vcpkg注册表中找到库的端口。我们需要一种方法来区分现有的 vcpkg port 概念和新的 artifacts 概念,因为这些命令可能是指其中之一。因此,我们引入了一个新的查找命令,它可以作为查找端口名称,或者查找工件名称。现有的搜索命令仍然以其现有的行为存在,只返回端口。

    试着用下面的命令找到一个工件,比如CMake。

    vcpkg find artifact cmake
    

    这将输出任何与所使用的短名称相匹配的东西,目前是下面这个。

    vcpkg-ce ('configure environment') is experimental and may change at any time.
     Artifact                       Version  Summary
     microsoft:tools/kitware/cmake  3.20.1   Kitware's cmake tool
    

    使用工件

    现在你已经找到了一个你想使用的工件,你可以用vcpkg use命令。试试这个命令来使用CMake。

    vcpkg use cmake 
    vcpkg-ce ('configure environment') is experimental and may change at any time.
     Artifact                           Version    Status     Dependency  Summary
    
     microsoft:tools/kitware/cmake      3.20.1     installed              Kitware's cmake tool
    
    Activating individual artifacts
    

    是的,你可以一次激活一个以上的工件。下面的命令在一个命令中激活了gcc、cmake和ninja,一个完整的C++构建系统。注意这是Arm GCC编译器,因为这是目前注册表中唯一的一个。

    vcpkg use gcc cmake ninja
    

    创建你自己的清单

    上例中的清单(vcpkg-configuration.json)也是用vcpkg创建的。要创建含有您自己所需工具的清单,请使用 vcpkg new。请确保在一个新目录下运行后续命令,而不是现有项目的子文件夹。

    vcpkg new
    

    将工件添加到清单中

    现在我们有了清单,并找到了我们想在项目中使用的工件,添加它们就很简单了。请注意,添加命令要求我们指定一个工件,因为它也可用于向清单添加端口。

    vcpkg add artifact cmake
    
    vcpkg-ce ('configure environment') is experimental and may change at any time.
    
     Artifact                       Version  Status     Dependency  Summary
    
     microsoft:tools/kitware/cmake  3.20.1   installed  *           Kitware's cmake tool
    
    Project c:\source\newprj activated
    

    现在你可以在vcpkg-configuration.json中检查你的源代码。其他任何使用您的项目的人都可以用一条命令安装 vcpkg,然后激活您清单中的工件,并在本地重现相同的结果。

    vcpkg的后续使用

    在上面的例子中,vcpkg在安装后可以在命令行中使用。有一个快速的方法可以让它回到你最喜欢的终端的新实例中。

    • Linux/macOS
    . ~/.vcpkg/vcpkg-init.sh
    
    • PowerShell
    . ~/.vcpkg/vcpkg-init.ps1
    
    • CMD Shell
    %USERPROFILE%\.vcpkg\vcpkg-init.cmd
    

    删除vcpkg

    这很有趣,你如何用上面的说明从你的系统中删除安装的vcpkg?只需删除你的主目录中的.vcpkg文件夹。通过安装或使用它,你的系统没有发生其他变化。

    使用你自己的注册表

    目前默认注册表中的工件仅限于我们一直在开发的以Azure RTOS为中心的嵌入式场景。在未来,这套工具将扩展到桌面开发场景。默认注册表可以在这里找到:https://github.com/microsoft/vcpkg-ce-catalog 。请注意,我们现在不接受对默认注册表添加工件的拉动请求。

    我们完全期待人们有他们自己想要使用的工件,或者提供给其他人使用。

    举个例子,如果你想使用一个较新的Arm编译器怎么办?我们的例子使用的是Azure RTOS项目的例子所设定的,所以这也是我们放入注册表的唯一一个例子。在下面的步骤中,我将展示我如何将一个新的Arm编译器添加到我自己的注册表中。你可以按照同样的步骤,针对你需要的工件进行修改,以创建你自己的工件注册表,供vcpkg使用。

    为了创建一个新的Arm gcc工件元数据文件,我查看了vcpkg-ce-catalog repo中gcc编译器的现有工件元数据,compilers/arm/gcc/ gcc-2020.10.0.yaml

    在我的本地机器上,我把这个文件复制到一个文件夹,myregistry,在同一个路径下,以保持一致性。然后我去Arm的网站上找到他们提供的最新编译器。然后我重新命名了元数据文件,使之与之匹配,即gcc-2021.10.0.yaml。我更新了文件中的版本字段,安装>解压下的工件URL,并添加了sha256信息。请注意,Arm只为他们的工件提供md5和,这意味着我必须先手动下载工件来生成我自己的sha256和来使用。你可以在我的个人GitHub仓库中找到这个文件,gcc-2021.10.0.yaml

    现在,为了测试这个,我创建了一个测试文件夹,并用vcpkg new创建了一个清单。然后我打开这个清单,添加了一个注册表部分,指向我的本地文件夹和工件元数据。

    {
        "registries": [
          {
            "name": "myregistry",
            "location": "c:/source/myregistry",
            "kind": "artifact"
          }
        ]
    }
    

    注意,我指定了完整的路径,像~这样的别名不被支持。 现在,为了找到这个条目,我指定了名称作为搜索查询的一部分。

    vcpkg find artifact myregistry:gcc
    
    vcpkg-ce ('configure environment') is experimental and may change at any time.
    Artifact                 Version    Summary
    myregistry:compilers/arm/gcc  2021.10.0  GCC compiler for ARM CPUs.
    

    经过验证后,我以同样的方式将其添加到清单中。

    vcpkg add artifact local:gcc
    
    vcpkg-ce ('configure environment') is experimental and may change at any time.
    Artifact                      Version    Status     Dependency Summary
    myregistry:compilers/arm/gcc  2021.10.0  installed  *          GCC compiler for ARM CPUs.
    
    Project c:\source\test activated
    

    现在我的清单看起来像这样。

    {
      "registries": [
        {
          "name": "myregistry",
          "location": "c:/source/myregistry",
          "kind": "artifact"
        }
      ],
      "requires": {
        "myregistry:compilers/arm/gcc": "* 2021.10.0"
      }
    }
    

    我不想与他人分享注册表使用本地路径的清单。支持网络路径,如果我只在内部共享,这也是可行的。请注意,我必须在位置栏中转义路径。

    "location": "\\\\myshare\\folder\\myregistry",
    

    我想在GitHub上分享我的注册表以支持这篇文章,这需要几个额外的步骤。第一个额外步骤是生成一个索引文件。为了做到这一点,我运行了以下实验性的命令(这在将来可能会有变化)。

    vcpkg z-ce regenerate c:/source/myregistry
    

    这为指定位置的所有工件元数据文件生成了一个index.yaml。

    "location": "https://github.com/robotdad/myregistry/archive/refs/heads/main.zip",
    

    为了使用发布在GitHub repo中的注册表,我需要指定提供存储库存档的端点。这样vcpkg就可以在一次请求中获得所有的工件元数据。对于GitHub repo来说,这可以在版本库下的/archive/refs/heads/main.zip路径中找到。在这个例子中,我在我的个人GitHub账户中发布了我的注册表,https://github.com/robotdad/myregistry ,其位置在清单中被指定如下。

    给我们提供反馈!

    我们很想听听你对vcpkg中新工件功能的看法。我们为提供这些功能的组件建立了一个单独的 repo,即 vcpkg-ce,你可以在那里提出你遇到的任何问题。下面的评论是开放的,或者你可以在Twitter(@VisualC)上找到我们,或者通过电子邮件:visualcpp@microsoft.com。随着vcpkg中工件功能的发展,你的想法对于我们创造一个优秀的开发者体验至关重要。

    浏览所有的包资源

    https://vcpkg.io/en/packages.html

    image

    比如搜索QT

    image

    新闻动态

    https://devblogs.microsoft.com/search?query=vcpkg

    image

    获取Vcpkg

    Windows上安装Vcpkg

    安装vcpkg有两个步骤:

    首先,克隆repo,然后运行引导脚本以产生vcpkg二进制文件

    这个repo可以在任何地方克隆,并且会包括引导后的vcpkg二进制文件,以及任何从命令行安装的库。建议CMake项目将vcpkg克隆为一个子模块,而MSBuild项目则全局安装。如果是全局安装,我们推荐一个简短的安装路径,比如:C:\src\vcpkgC:\dev\vcpkg,否则你可能会在某些端口构建系统中遇到路径问题。

    第1步:克隆vcpkg仓库

    git clone https://github.com/Microsoft/vcpkg.git
    

    image

    在这样做之前,请确保你在你想要安装该工具的目录中。

    第2步:运行bootstrap脚本来构建vcpkg

    我们进入Git拉取后的vcpkg目录。

    image

    找到其中的bootstrap-vcpkg.bat文件。

    image

    @echo off
    powershell.exe -NoProfile -ExecutionPolicy Bypass "& {& '%~dp0scripts\bootstrap.ps1' %*}"
    

    既然这个批处理文件实际上是调用scripts\bootstrap.ps1,那我们看看这葫芦里到底装了什么药。

    [CmdletBinding()]
    param(
        $badParam,
        [Parameter(Mandatory=$False)][switch]$win64 = $false,
        [Parameter(Mandatory=$False)][string]$withVSPath = "",
        [Parameter(Mandatory=$False)][string]$withWinSDK = "",
        [Parameter(Mandatory=$False)][switch]$disableMetrics = $false
    )
    Set-StrictMode -Version Latest
    # Powershell2-compatible way of forcing named-parameters
    if ($badParam)
    {
        if ($disableMetrics -and $badParam -eq "1")
        {
            Write-Warning "'disableMetrics 1' is deprecated, please change to 'disableMetrics' (without '1')."
        }
        else
        {
            throw "Only named parameters are allowed."
        }
    }
    
    if ($win64)
    {
        Write-Warning "-win64 no longer has any effect; ignored."
    }
    
    if (-Not [string]::IsNullOrWhiteSpace($withVSPath))
    {
        Write-Warning "-withVSPath no longer has any effect; ignored."
    }
    
    if (-Not [string]::IsNullOrWhiteSpace($withWinSDK))
    {
        Write-Warning "-withWinSDK no longer has any effect; ignored."
    }
    
    $scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
    $vcpkgRootDir = $scriptsDir
    while (!($vcpkgRootDir -eq "") -and !(Test-Path "$vcpkgRootDir\.vcpkg-root"))
    {
        Write-Verbose "Examining $vcpkgRootDir for .vcpkg-root"
        $vcpkgRootDir = Split-path $vcpkgRootDir -Parent
    }
    
    Write-Verbose "Examining $vcpkgRootDir for .vcpkg-root - Found"
    
    $versionDate = '2022-02-24'
    if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64' -or $env:PROCESSOR_IDENTIFIER -match "ARMv[8,9] \(64-bit\)") {
        & "$scriptsDir/tls12-download.exe" github.com "/microsoft/vcpkg-tool/releases/download/$versionDate/vcpkg-arm64.exe" "$vcpkgRootDir\vcpkg.exe"
    } else {
        & "$scriptsDir/tls12-download.exe" github.com "/microsoft/vcpkg-tool/releases/download/$versionDate/vcpkg.exe" "$vcpkgRootDir\vcpkg.exe"
    }
    
    Write-Host ""
    
    if ($LASTEXITCODE -ne 0)
    {
        Write-Error "Downloading vcpkg.exe failed. Please check your internet connection, or consider downloading a recent vcpkg.exe from https://github.com/microsoft/vcpkg-tool with a browser."
        throw
    }
    
    if ($disableMetrics)
    {
        Set-Content -Value "" -Path "$vcpkgRootDir\vcpkg.disable-metrics" -Force
    }
    elseif (-Not (Test-Path "$vcpkgRootDir\vcpkg.disable-metrics"))
    {
        # Note that we intentionally leave any existing vcpkg.disable-metrics; once a user has
        # opted out they should stay opted out.
        Write-Host @"
    Telemetry
    ---------
    vcpkg collects usage data in order to help us improve your experience.
    The data collected by Microsoft is anonymous.
    You can opt-out of telemetry by re-running the bootstrap-vcpkg script with -disableMetrics,
    passing --disable-metrics to vcpkg on the command line,
    or by setting the VCPKG_DISABLE_METRICS environment variable.
    
    Read more about vcpkg telemetry at docs/about/privacy.md
    "@
    }
    

    运行bootstrap-vcpkg.bat之后,我们看到,实际上第一步,它就是从Github上下载vcpkg.exe文件,它将被保存到vcpkg\vcpkg.exe位置。

    image

    你要是觉得太慢了,可以自己下载,放到它对应的位置即可。

    image

    从这个地址我们也发现了另外一个仓库:https://github.com/microsoft/vcpkg-tool

    其实这个文件就是被发布在它这个仓库的发布页的:https://github.com/microsoft/vcpkg-tool/releases

    一段时间后,我们就可以看到vcpkg.exe文件了。

    image

    第3步:缩短并优化vcpkg的编译路径

    由于编译路径过程会导致很多失败,所以建议一开始就把vcpkg这个文件夹设立在磁盘的根目录。

    并且,如果你的SSD还有足够空间(>150GB),建议把vcpkg放到SSD磁盘会节约很多编译时间。

    出于缩短整个编译路径的考虑,我们这里不仅把vcpkg这个文件夹重命名为v,而且还把它挪到磁盘根目录。

    所以最终它的路径是: F:\v

    image

    第4步:配置vcpkg到环境变量中并验证

    打开Windows 11的搜索,输入"环境变量",找到"编辑系统环境变量",进入"系统属性"对话框,点击进入"环境变量"设置页。

    image

    image

    找到"系统变量"组中的"Path"变量项,双击或者点击进入编辑页面。

    image

    点击新建按钮,把vcpkg所在目录填写进去。

    image

    一路点击确定退出即可。

    这时候再打开Windows终端,即可识别vcpkg指令了。

    vcpkg --version
    

    image

    使用Vcpkg

    支持的命令总览(vcpkg --help)

    image

    vcpkg search [pat]              Search for packages available to be built
    vcpkg install <pkg>...          Install a package
    vcpkg remove <pkg>...           Uninstall a package
    vcpkg remove --outdated         Uninstall all out-of-date packages
    vcpkg list                      List installed packages
    vcpkg update                    Display list of packages for updating
    vcpkg upgrade                   Rebuild all outdated packages
    vcpkg x-history <pkg>           (Experimental) Shows the history of CONTROL versions of a package
    vcpkg hash <file> [alg]         Hash a file by specific algorithm, default SHA512
    vcpkg help topics               Display the list of help topics
    vcpkg help <topic>              Display help for a specific topic
    
    vcpkg integrate install         Make installed packages available user-wide. Requires admin
                                    privileges on first use
    vcpkg integrate remove          Remove user-wide integration
    vcpkg integrate project         Generate a referencing nuget package for individual VS project use
    vcpkg integrate powershell      Enable PowerShell tab-completion
    
    vcpkg export <pkg>... [opt]...  Exports a package
    vcpkg edit <pkg>                Open up a port for editing (uses %EDITOR%, default 'code')
    vcpkg create <pkg> <url> [archivename]
                                    Create a new package
    vcpkg x-init-registry <path>    Initializes a registry in the directory <path>
    vcpkg format-manifest --all     Formats all vcpkg.json files. Run this before committing to vcpkg.
    vcpkg owns <pat>                Search for files in installed packages
    vcpkg depend-info <pkg>...      Display a list of dependencies for packages
    vcpkg env                       Creates a clean shell environment for development or compiling
    vcpkg version                   Display version information
    vcpkg contact                   Display contact information to send feedback
    

    列举支持的平台(vcpkg help triplet)

    vcpkg help triplet
    

    image

    目前内置的平台有:

    • arm-uwp
    • arm64-windows
    • x64-linux
    • x64-osx
    • x64-uwp
    • x64-windows-static
    • x64-windows
    • x86-windows

    社区支持的平台有:

    • arm-android
    • arm-ios
    • arm-linux
    • arm-mingw-dynamic
    • arm-mingw-static
    • arm-neon-android
    • arm-windows-static
    • arm-windows
    • arm64-android
    • arm64-ios
    • arm64-linux
    • arm64-mingw-dynamic
    • arm64-mingw-static
    • arm64-osx-dynamic
    • arm64-osx
    • arm64-uwp
    • arm64-windows-static-md
    • arm64-windows-static
    • armv6-android
    • ppc64le-linux
    • s390x-linux
    • wasm32-emscripten
    • x64-android
    • x64-freebsd
    • x64-ios
    • x64-linux-release
    • x64-mingw-dynamic
    • x64-mingw-static
    • x64-openbsd
    • x64-osx-dynamic
    • x64-osx-release
    • x64-windows-release
    • x64-windows-static-md
    • x86-android
    • x86-freebsd
    • x86-ios
    • x86-mingw-dynamic
    • x86-mingw-static
    • x86-uwp
    • x86-windows-static-md
    • x86-windows-static
    • x86-windows-v120

    对Vcpkg来说,默认采用的平台分别为:

    • x86-windows
    • x64-linux
    • x64-osx
    vcpkg search $keyword
    

    这个命令将从Vcpkg的Github仓库的目录ports清单中进行检索。

    image

    例如:

    vcpkg search
    

    image

    vcpkg search azure
    

    image

    如果你负责的组件没有被收纳,还可以提交issues来反馈。

    image

    vcpkg search sqlite
    

    image

    编译并安装指定可用库(vcpkg install)

    vcpkg install $packageName
    

    例如:

    vcpkg install azure-core-cpp
    

    image

    该命令的步骤是:

    1. 环境初始化
    2. 下载源代码(如果已经在cache中,则不下载)
    3. 校验文件有效性
    4. 解压缩源代码
    5. 利用配套工具配置源码工程
    6. 编译源码。一般会同时编译Release和Debug版本。
    7. 把编译好的文件拷贝到相关目录中去
    Computing installation plan...
    The following packages will be built and installed:
        azure-core-cpp[core,curl,http,winhttp]:x86-windows -> 1.4.0
      * curl[core,non-http,schannel,ssl,sspi]:x86-windows -> 7.81.0
      * vcpkg-cmake[core]:x64-windows -> 2022-01-19
      * vcpkg-cmake-config[core]:x64-windows -> 2022-02-06
      * zlib[core]:x86-windows -> 1.2.11#13
    Additional packages (*) will be modified to complete this operation.
    Detecting compiler hash for triplet x64-windows...
    A suitable version of git was not found (required v2.35.1). Downloading portable git v2.35.1...
    Downloading git...
    

    在这里,我们看到它是发现你缺啥就补啥,它在vcpkg根目录下面创建了一个名为downloads的文件夹,然后将检索到的依赖文件下载到这里面。

    image

    好处就是,应该是公共的东西就只下载一次了,但是不友好的就是这个下载没有进度条,你也不知道他到底情况如何了。

    image

    下载完之后,会被解压到同目录下有个tools文件夹里面,解压出来用。

    image

    看得出,啥依赖都下了,就是不管你系统有没有,它都单独给你弄一套解压在这里,这样的好处就是,真正的它只用自己配套的,不会影响你的,坏处就是,确实要消耗一些带宽和空间。

    image

    最终完成了编译,它优秀的一面就是,这过程中,它分析了依赖什么,会先处理好依赖的,在最终来编译我们的目标包的源码,然后得到输出。

    vcpkg install sqlite3
    

    image

    Building package sqlite3[core]:x86-windows...
    -- Downloading https://sqlite.org/2021/sqlite-amalgamation-3370100.zip -> sqlite-amalgamation-3370100.zip...
    -- Extracting source F:/ToolSpace/vcpkg/downloads/sqlite-amalgamation-3370100.zip
    -- Applying patch fix-arm-uwp.patch
    -- Using source at F:/ToolSpace/vcpkg/buildtrees/sqlite3/src/3370100-a1573e1602.clean
    -- Found external ninja('1.10.2').
    -- Configuring x86-windows
    -- Building x86-windows-dbg
    -- Building x86-windows-rel
    

    拉取了所有的依赖组件之后,它就开始拉取真正的目标包的源码,最终源码会安置在buildtrees目录。

    image

    然后它会编译目标包源码,最终将生成的目标包文件生成到packages目录。

    image

    image

    最后我看它,还存储了一个二进制缓存,目录有点特别,C:\Users\CurrentUser\AppData\Local\vcpkg\archives

    image

    image

    对我们而言,最终还是拿编译后的文件了,这时候,我们找到vcpkg\packages\sqlite3_x86-windows\bin这个目录,看到sqlite3.dll文件已经在这里了。

    image

    其实,我们还可以指定平台来安装,比如:

    vcpkg install sqlite3:x64-windows
    

    image

    最终也就得到了X64的sqlite3文件了。

    image

    另外,你还可以同时安装多个,指定多个平台

    vcpkg install sqlite3:x86-uwp zlib:x64-windows
    

    image

    其次,这里还是有一些隐蔽的参数可以设定的,比如有些目标包编译会因为路径过程而失败,我们也可以在安装命令这里直接指定编译树的路径,这样来达到缩短最终编译路径的目的。

    vcpkg install qt5-webengine --x-buildtrees-root=F:\b\
    

    查看已拉取并安装的可用库(vcpkg list)

    vcpkg list
    

    这个就可以看到本地有哪些编译好的库了。

    image

    导出已安装的可用库(vcpkg export)

    vcpkg export $packageName $exportFileType
    

    其中$exportFileType是指导出时的打包格式,目前支持五种导出格式:

    参数 格式
    --raw 以不打包的目录格式导出
    --nuget 以nuget包形式导出
    --ifw 我也不知道这是啥格式
    --zip 以zip压缩包形式导出
    --7zip 以7z压缩包形式导出
    --x-chocolatey 以Chocolatey包形式导出
    --prefab 以Prefab形式导出

    例如:

    vcpkg export zlib:x64-windows --7zip
    

    image

    我们看到了,导出后的文件保存在F:\vcpkg\vcpkg-export-20220308-213627.7z位置了。

    image

    导入已备份的可用库(vcpkg import)

    vcpkg import $importFilePath
    

    例如:

    vcpkg import vcpkg-export-20220308-213627.7z
    

    Vcpkg与Visual Studio集成

    好不容易一键解决了编译和安装的问题,但是在Visual Studio实际编写项目代码过程中,比较麻烦的就是我们要一个个指定目录到已编译好的包位置,这很麻烦,我们,可以通过集成命令,一口气把所有的已安装的目录和头文件配置到Visual Studio中。

    安装集成环境

    vcpkg integrate install
    

    image

    对Cmake项目来说,还需要配置好环境变量:

    -DCMAKE_TOOLCHAIN_FILE=F:/ToolSpace/vcpkg/scripts/buildsystems/vcpkg.cmake
    

    移除集成环境

    vcpkg integrate remove
    

    image

    验证集成环境

    https://github.com/TaylorShi/HelloVcpkg

    先根据Sqlite官方案例准备一个演示项目,然后把代码贴进去。

    image

    这时候,我们看到sqlite3.h这个头文件没有被正确引用,所以注定一堆报错。

    那么我们现在执行下集成环境,再回来看看效果。

    image

    image

    一个报错都没有了,还能编译通过,就是这么神奇!

    Vcpkg实战演练

    Vcpkg编译Chromium(Base)

    Chromium是大名鼎鼎的Chrome浏览器的开源项目版本,在Vcpkg里面目前有个chromium-base项目是可用的,我们来试试它。

    先搜索下chromium

    vcpkg search chromium
    

    image

    发现找到一个chromium-base的包可用,对应的版本目前是86.0.4199.1

    vcpkg install chromium-base
    
    Error: chromium-base[core] is only supported on 'x64 & (osx | windows | linux) & !uwp'
    

    image

    直接来了一个报错,因为在Windows上vcpkg默认平台是x86-windows,但是偏偏Chromiunm只支持x64,那么只能指定下了。

    vcpkg install chromium-base:x64-windows
    

    image

    这下还不错,解析到了,开始跑。

    image

    还是挂了。

    找到日志:F:\ToolSpace\vcpkg\buildtrees\chromium-base\generate-x64-windows-dbg-err.log

    发现内容是:

    Traceback (most recent call last):
      File "F:/ToolSpace/vcpkg/buildtrees/chromium-base/src/25ce732/build/vs_toolchain.py", line 578, in <module>
        sys.exit(main())
      File "F:/ToolSpace/vcpkg/buildtrees/chromium-base/src/25ce732/build/vs_toolchain.py", line 574, in main
        return commands[sys.argv[1]](*sys.argv[2:])
      File "F:/ToolSpace/vcpkg/buildtrees/chromium-base/src/25ce732/build/vs_toolchain.py", line 389, in CopyDlls
        _CopyDebugger(target_dir, target_cpu)
      File "F:/ToolSpace/vcpkg/buildtrees/chromium-base/src/25ce732/build/vs_toolchain.py", line 425, in _CopyDebugger
        (debug_file, full_path))
    Exception: dbghelp.dll not found in "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll"
    You must installWindows 10 SDK version 10.0.19041.0 including the "Debugging Tools for Windows" feature.
    

    image

    确实找不到Debuggers\x64\dbghelp.dll这个文件夹和路径。

    原来它对Windows 10 SDK 19041下面一个Debugging Tools for Window存在依赖,好吧,找了半天没找到,但是我反应过来,可能是要把UWP那套补装下。

    image

    结果弄完还是没有,我查了下,原来这玩意是个安装Windows 10 SDK 19041时候的可选组件,那么Visual Studio这个默认安装是不勾选的,那怎么办?

    image

    急中生智,想到一个办法,那就是前往系统的设置-应用-应用和功能,我们找到19041这个SDK,修改它。

    image

    image

    果然没有勾选这个Debugging Tools for Windows,江湖人称WinDbg,马上勾选它,执行Change。

    image

    image

    image

    image

    这下是真的有了,好了,我们把命令重新试试。

    image

    牛逼牛逼,最后真的可以了。

    image

    image

    怎么弄完就一个chromium_base.dll文件,这是干嘛的?不明白了

    我还找到Chromium关于对19041 SDK及Debugging Tools For Windows的依赖说明

    You must have the version 10.0.19041 or higher Windows 10 SDK installed. This can be installed separately or by checking the appropriate box in the Visual Studio Installer.

    The SDK Debugging Tools must also be installed. If the Windows 10 SDK was installed via the Visual Studio installer, then they can be installed by going to: Control Panel → Programs → Programs and Features → Select the “Windows Software Development Kit” → Change → Change → Check “Debugging Tools For Windows” → Change. Or, you can download the standalone SDK installer and use it to install the Debugging Tools.

    Vcpkg编译QtWebEngine(6.2.3)

    我们挑战下编译QtWebEngine,这是QT旗下一个Hybrid组件,说白了就是基于Chromium封装的QT组件,之前一直很难编译过去。

    vcpkg install qtwebengine
    

    结果报错了

    image

    ❯ vcpkg install qtwebengine
    Computing installation plan...
    Error: qtwebengine[core] is only supported on '!static & !((arm | x86) & windows)'
    

    这是啥意思,意思就是这个目标包,不能支持静态的、ARM的、X86的,那么还剩下什么?其实就是x64-windows

    vcpkg install qtwebengine:x64-windows
    

    果然可以,只是这依赖性也太吓人了吧。

    image

    ❯ vcpkg install qtwebengine:x64-windows
    Computing installation plan...
    The following packages will be built and installed:
      * brotli[core]:x64-windows -> 1.0.9#2
      * bzip2[core]:x64-windows -> 1.0.8#2
      * double-conversion[core]:x64-windows -> 3.2.0
      * egl-registry[core]:x64-windows -> 2021-11-23
      * freetype[brotli,bzip2,core,png,zlib]:x64-windows -> 2.11.1
      * harfbuzz[core]:x64-windows -> 3.2.0#1
      * icu[core]:x64-windows -> 69.1#18
      * libjpeg-turbo[core]:x64-windows -> 2.1.3
      * libpng[core]:x64-windows -> 1.6.37#16
      * libpq[core,openssl,zlib]:x64-windows -> 12.9#1
      * opengl-registry[core]:x64-windows -> 2021-11-17
      * openssl[core]:x64-windows -> 1.1.1m#2
      * pcre2[core]:x64-windows -> 10.39#2
      * qtbase[brotli,concurrent,core,dbus,default-features,doubleconversion,freetype,gui,harfbuzz,icu,jpeg,network,openssl,pcre2,png,sql,sql-psql,sql-sqlite,testlib,widgets,zstd]:x64-windows -> 6.2.3
      * qtdeclarative[core]:x64-windows -> 6.2.3
      * qtshadertools[core]:x64-windows -> 6.2.3
      * qttools[assistant,core,designer,linguist]:x64-windows -> 6.2.3
        qtwebengine[core,default-features]:x64-windows -> 6.2.3
      * vcpkg-tool-meson[core]:x64-windows -> 0.60.2#2
      * vcpkg-tool-nodejs[core]:x64-windows -> 14.17.4
      * zstd[core]:x64-windows -> 1.5.2#1
    Additional packages (*) will be modified to complete this operation.
    

    但是Vcpkg牛逼的时刻来了,哪怕这么多依赖项,它也不带怕的,缺啥补啥。

    image

    然后迷之自信失败了。

    image

    Error: Building package libpq:x64-windows failed with: BUILD_FAILED
    

    卡在一个叫libpq:x64-windows的家伙这里,它其实是postgresql这个数据库的别名,提示我们看错误日志。

    F:\ToolSpace\vcpkg\buildtrees\libpq\build-libpq-x64-windows-RELEASE-out.log
    F:\ToolSpace\vcpkg\buildtrees\libpq\build-libpq-x64-windows-RELEASE-err.log
    

    image

    The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead. at F:\ToolSpace\vcpkg\buildtrees\libpq\x64-windows-rel\src\tools\msvc/Mkvcbuild.pm line 92.
    

    说我Visual Studio版本太高了?2022妨碍了它吗?果然确实之前有人反馈过,不过还不是当前的12.9版本的postgresql,直到14.0版本都有问题。

    image

    说实话,我也用它这个git补丁试过,但是对不上,因为它这个补丁是针对14版本的,而Vcpkg当前指定的这个版本是12.9,这个补丁打下去失败告终。

    从补丁内容来看,看来是Visual Studio版本在2019应该可以用。

    image

    那么接下来,只能割袍断义,对不起了,Visual Studio 2022,我先安装个Visual Studio 2019来补位,顺便还要把2022给卸载了。

    image

    但是还是失败了,过不去,暂时留个Issue在这里:https://github.com/microsoft/vcpkg/issues/23428

    看到,有个人提示说,让我去补装下Visual Studio的英语语言包,这是啥意思?因为我提问不标准吗?死马当活马医治。

    image

    打开Visual Studio Installer这个程序,修改当前的Visual Studio安装,切换到语言包这里,我们把英语勾选上。

    image

    再试试这个受阻的vcpkg install libpq:x64-windows,竟然成功编译了,这是不是语言歧视?

    image

    好了,突破了libpq,我们就继续走安装命令了。

    image

    到了-- Building x64-windows-dbg这里,不知道走了多久,感觉卡死了一样,没啥动静了。

    image

    还好可以断点续编,就是之前编译过的包就不会重复编译了。

    编译到x64-windows-rel的时候又失败了,看错误,其实没说什么,但是很眼熟,这这个哥们情况有点类似:[qtwebengine] build failure #21981,看给出答案就是因为路径还是过长了,所以我临时决定,再把整个vcpkg文件夹直接缩写成v试试看。

    image

    再不行,真的就只能用--x-buildtrees-root来指定一个了。

    image

    没错,这样就可以了,虽然等了很久很久,但是它最后成功了。

    image

    Installing package qtwebengine[core,default-features]:x64-windows...
    Elapsed time for package qtwebengine:x64-windows: 5.036 h
    
    Total elapsed time: 5.037 h
    

    不夸张的说,光是编译这个目标库,就花了5个小时,小伙伴们,这可不是闹着玩的。

    当然我之所以这么慢还有个原因是,我把vcpkg放到机械硬盘了,听我朋友说,放在固态硬盘的话只要一个小时哈。

    image

    image

    DLL纯重114MB

    image

    资源纯重15.1MB

    image

    说到这里,我觉得有必要把他导出来备份下:

    vcpkg export qtwebengine:x64-windows --zip
    
    ❯ vcpkg export qtwebengine:x64-windows --zip
    The following packages are already built and will be exported:
      * brotli:x64-windows
      * bzip2:x64-windows
      * double-conversion:x64-windows
      * egl-registry:x64-windows
      * freetype:x64-windows
      * harfbuzz:x64-windows
      * icu:x64-windows
      * libjpeg-turbo:x64-windows
      * libpng:x64-windows
      * libpq:x64-windows
      * opengl-registry:x64-windows
      * openssl:x64-windows
      * pcre2:x64-windows
      * qtbase:x64-windows
      * qtdeclarative:x64-windows
      * qtshadertools:x64-windows
      * qttools:x64-windows
        qtwebengine:x64-windows
      * sqlite3:x64-windows
      * vcpkg-cmake:x64-windows
      * vcpkg-cmake-config:x64-windows
      * vcpkg-tool-meson:x64-windows
      * vcpkg-tool-nodejs:x64-windows
      * zlib:x64-windows
      * zstd:x64-windows
    Additional packages (*) need to be exported to complete this operation.
    

    image

    结果这个包太吓人了。

    image

    采用zip格式太大了,还是改用7zip吧。

    vcpkg export qtwebengine:x64-windows --7zip
    

    然后我们把它改名为qt-6.2.3-webengine-x64-windows-export-20220312-013044.7z

    image

    体积还是下降了不少,只有1.29GB了。

    Vcpkg编译QtWebEngine(5.15.3)

    前面编译的QtWebEngine时6版本,但是主流的QT大家很多还是5版本,尤其是LTS v5.15这个,从库表里面看到,这里就有个专门的5版本的目标包可用,那我们试试?

    image

    vcpkg install qt5-webengine
    

    可以用,但是这依赖列表,能把你吓死。

    ❯ vcpkg install qt5-webengine
    Computing installation plan...
    The following packages will be built and installed:
      * atlmfc[core]:x86-windows -> 0#1
      * brotli[core]:x86-windows -> 1.0.9#2
      * bzip2[core]:x86-windows -> 1.0.8#2
      * double-conversion[core]:x86-windows -> 3.2.0
      * egl-registry[core]:x86-windows -> 2021-11-23
      * freeglut[core]:x86-windows -> 3.2.1#7
      * freetype[brotli,bzip2,core,png,zlib]:x86-windows -> 2.11.1
      * harfbuzz[core]:x86-windows -> 3.2.0#1
      * icu[core]:x86-windows -> 69.1#18
      * jasper[core,opengl]:x86-windows -> 2.0.33#3
      * libjpeg-turbo[core]:x86-windows -> 2.1.3
      * liblzma[core]:x86-windows -> 5.2.5#5
      * libpng[core]:x86-windows -> 1.6.37#16
      * libwebp[core,nearlossless,simd,unicode]:x86-windows -> 1.2.1
      * opengl[core]:x86-windows -> 0.0#9
      * openssl[core]:x86-windows -> 1.1.1m#2
      * pcre2[core]:x64-windows -> 10.39#2
      * pcre2[core]:x86-windows -> 10.39#2
      * pkgconf[core]:x64-windows -> 1.8.0#2
      * qt5-activeqt[core]:x86-windows -> 5.15.3
      * qt5-base[core]:x64-windows -> 5.15.3
      * qt5-base[core]:x86-windows -> 5.15.3
      * qt5-declarative[core]:x86-windows -> 5.15.3
      * qt5-graphicaleffects[core]:x86-windows -> 5.15.3
      * qt5-imageformats[core]:x86-windows -> 5.15.3
      * qt5-location[core]:x86-windows -> 5.15.3
      * qt5-quickcontrols[core]:x86-windows -> 5.15.3
      * qt5-quickcontrols2[core]:x86-windows -> 5.15.3
      * qt5-serialport[core]:x86-windows -> 5.15.3
      * qt5-svg[core]:x86-windows -> 5.15.3
      * qt5-tools[core]:x86-windows -> 5.15.3
      * qt5-webchannel[core]:x86-windows -> 5.15.3
        qt5-webengine[core]:x86-windows -> 5.15.3
      * sqlite3[core]:x86-windows -> 3.37.2#1
      * sqlite3[core]:x64-windows -> 3.37.2#1
      * tiff[core,jpeg,lzma,zip]:x86-windows -> 4.3.0#6
      * vcpkg-pkgconfig-get-modules[core]:x64-windows -> 2022-02-10
      * zlib[core]:x86-windows -> 1.2.11#13
      * zstd[core]:x64-windows -> 1.5.2#1
      * zstd[core]:x86-windows -> 1.5.2#1
    Additional packages (*) will be modified to complete this operation.
    

    无所谓了,强大的Vcpkg就是为了让你躺平的。

    image

    过去快个把小时了,它还在弄,只要没失败就行!

    image

    失败来了,qt5-webengine's buildsystem uses very long paths and may fail on your system.

    image

    之前我把vcpkg放在F:\ToolSpace\vcpkg了,多了一层路径,我干脆把它往上挪一层吧。

    image

    同时记得把之前环境变量里面Path那个一起改了,不然vcpkg命令识别不了了。

    image

    多说一句,之前也看到过关于一个路径过程的Issue,这里介绍了另外一个办法就是可以追加参数,指定另外一个buildtrees位置:vcpkg install qt5-webengine --x-buildtrees-root=F:\b\,由此来看,vcpkg设计的还是蛮人性化的。

    看到下面这些提示,你也知道门槛多高了,要求100GB以上空间。

    -- qt5-webengine requires a lot of free disk space (>100GB), ram (>8 GB) and time (>2h per configuration) to be successfully build.
    -- As such qt5-webengine is currently experimental.
    -- If qt5-webengine fails post build validation please open up an issue.
    -- If it fails due to post validation the successfully installed files can be found in F:/vcpkg/packages/qt5-webengine_x86-windows
    -- and just need to be copied into F:/vcpkg/installed/x86-windows
    

    看起来情况不妙,还是失败了,然后从绝大多数需求出发,我们估计要把目标平台改成X64这样比较好,所以我们切换到命令:

    vcpkg install qt5-webengine:x64-windows
    

    image

    ❯ vcpkg install qt5-webengine:x64-windows
    Computing installation plan...
    The following packages will be built and installed:
        qt5-webengine[core]:x64-windows -> 5.15.3
    Detecting compiler hash for triplet x64-windows...
    -- Automatically setting HTTP(S)_PROXY environment variables to 127.0.0.1:7890
    Restored 0 packages from C:\Users\TaylorShi\AppData\Local\vcpkg\archives in 522.1 us. Use --debug to see more details.
    Starting package 1/1: qt5-webengine:x64-windows
    Building package qt5-webengine[core]:x64-windows...
    -- qt5-webengine requires a lot of free disk space (>100GB), ram (>8 GB) and time (>2h per configuration) to be successfully build.
    -- As such qt5-webengine is currently experimental.
    -- If qt5-webengine fails post build validation please open up an issue.
    -- If it fails due to post validation the successfully installed files can be found in F:/v/packages/qt5-webengine_x64-windows
    -- and just need to be copied into F:/v/installed/x64-windows
    -- Found external ninja('1.10.2').
    

    暂时以失败告终,看起来是一个补丁的错误,不知道怎么修复,那么就先提个Issue

    -- Applying patch common.pri.patch
    -- Applying patch gl.patch
    -- Applying patch build_1.patch
    CMake Error at scripts/cmake/z_vcpkg_apply_patches.cmake:61 (message):
      Applying patch failed: Checking patch
      src/3rdparty/chromium/third_party/angle/BUILD.gn...
    
      error: while searching for:
    
        # Enable more default warnings on Windows.
        if (is_win) {
          cflags += [
            "/we4244",  # Conversion: possible loss of data.
            "/we4456",  # Variable shadowing.
            "/we4458",  # declaration hides class member.
            "/we4715",  # not all control paths return a value
    
    
    
      error: patch failed: src/3rdparty/chromium/third_party/angle/BUILD.gn:126
    
      error: src/3rdparty/chromium/third_party/angle/BUILD.gn: patch does not
      apply
    
    Call Stack (most recent call first):
      scripts/cmake/vcpkg_extract_source_archive.cmake:230 (z_vcpkg_apply_patches)
      scripts/cmake/vcpkg_extract_source_archive_ex.cmake:32 (vcpkg_extract_source_archive)
      installed/x64-windows/share/qt5/qt_download_submodule.cmake:32 (vcpkg_extract_source_archive_ex)
      installed/x64-windows/share/qt5/qt_submodule_installation.cmake:5 (qt_download_submodule)
      ports/qt5-webengine/portfile.cmake:58 (qt_submodule_installation)
      scripts/ports.cmake:145 (include)
    
    
    Error: Building package qt5-webengine:x64-windows failed with: BUILD_FAILED
    

    好在官方的同志帮忙修复了这个,但是目前还在Code Review,还没完全合并进来。

    如果要提前试试,可以基于Github CLI,把这个PR分支拉取下来,怎么安装github Cli可以用Winget:

    winget install GitHub.cli
    

    然后要登录下你的账号

    gh auth login
    

    接下来我们就可以回到v目录来拉取这个PR了,拉取下来之后,它会自动切换到那个修复的分支上。

    gh pr checkout 23484
    

    image

    也就是说,这时候V已经是切换到了你想要的这个分支了,我们可以试试编译。

    vcpkg install qt5-webengine:x64-windows
    
    ❯ vcpkg install qt5-webengine:x64-windows
    Computing installation plan...
    The following packages will be built and installed:
        qt5-webengine[core]:x64-windows -> 5.15.3#1
    Detecting compiler hash for triplet x64-windows...
    -- Automatically setting HTTP(S)_PROXY environment variables to 127.0.0.1:7890
    Restored 0 packages from C:\Users\TaylorShi\AppData\Local\vcpkg\archives in 245.5 us. Use --debug to see more details.
    Starting package 1/1: qt5-webengine:x64-windows
    Building package qt5-webengine[core]:x64-windows...
    -- qt5-webengine requires a lot of free disk space (>100GB), ram (>8 GB) and time (>2h per configuration) to be successfully build.
    -- As such qt5-webengine is currently experimental.
    -- If qt5-webengine fails post build validation please open up an issue.
    -- If it fails due to post validation the successfully installed files can be found in C:/v/packages/qt5-webengine_x64-windows
    -- and just need to be copied into C:/v/installed/x64-windows
    -- Found external ninja('1.10.2').
    -- Using cached qtwebengine-everywhere-opensource-src-5.15.3.tar.xz.
    -- Extracting source C:/v/downloads/qtwebengine-everywhere-opensource-src-5.15.3.tar.xz
    -- Applying patch common.pri.patch
    -- Applying patch gl.patch
    -- Applying patch build_1.patch
    -- Applying patch build_2.patch
    -- Using source at C:/v/buildtrees/qt5-webengine/src/5.15.3-8f20289af4.clean
    -- Using cached msys-mingw-w64-i686-pkg-config-0.29.2-3-any.pkg.tar.zst.
    -- Using cached msys-mingw-w64-i686-libwinpthread-git-9.0.0.6373.5be8fcd83-1-any.pkg.tar.zst.
    -- Using msys root at C:/v/downloads/tools/msys2/9a1ec3f33446b195
    -- Configuring x64-windows-rel
    -- Configuring x64-windows-rel done
    -- Configuring x64-windows-dbg
    -- Configuring x64-windows-dbg done
    -- Package build-x64-windows-dbg
    -- Package build-x64-windows-rel
    -- Package install-x64-windows-dbg
    -- Package install-x64-windows-rel
    -- Installing: C:/v/packages/qt5-webengine_x64-windows/share/qt5-webengine/copyright
    -- Performing post-build validation
    -- Performing post-build validation done
    Stored binary cache: C:\Users\TaylorShi\AppData\Local\vcpkg\archives\08\08927a1463de68863ba74d2325ef3ce6a99c627358a2f19b98aeac3dfa8e29f0.zip
    Installing package qt5-webengine[core]:x64-windows...
    Elapsed time for package qt5-webengine:x64-windows: 9.296 min
    
    Total elapsed time: 9.403 min
    
    The package qt5-webengine provides CMake targets:
    
        find_package(Qt5Gui CONFIG REQUIRED)
        target_link_libraries(main PRIVATE Qt5::QPdfPlugin)
    
        find_package(Qt5Pdf CONFIG REQUIRED)
        target_link_libraries(main PRIVATE Qt::Pdf Qt5::Pdf Qt::PdfPrivate Qt5::PdfPrivate)
    
        find_package(Qt5PdfWidgets CONFIG REQUIRED)
        target_link_libraries(main PRIVATE Qt::PdfWidgets Qt5::PdfWidgets Qt::PdfWidgetsPrivate Qt5::PdfWidgetsPrivate)
    

    完美的,一切顺利,它真的成功了,太棒了。

    image

    这里还是将这个编译结果导出来,以免丢失。

    vcpkg export qt5-webengine:x64-windows --7zip
    

    最后我们进行一次重命名:qt-5.15.3-webengine-x64-windows-export-20220311-113825.7z

    image

    体积只有381MB

    Vcpkg编译Chromium Embedded Framework(CEF)

    大家的呼吁

    Vcpkg编译FFmpeg

    查找下FFmpeg

    vcpkg search FFmpeg
    

    image

    还行,有个4.4.1的版本可以编译用。

    vcpkg install ffmpeg
    

    image

    还行,一切顺利,没让人操什么心

    image

    image

    Vcpkg编译QT(6.2.3)

    vcpkg install qt:x64-windows
    

    image

    ❯ vcpkg install qt:x64-windows
    Computing installation plan...
    A suitable version of cmake was not found (required v3.22.2). Downloading portable cmake v3.22.2...
    Downloading cmake...
      https://github.com/Kitware/CMake/releases/download/v3.22.2/cmake-3.22.2-windows-i386.zip -> C:\v\downloads\cmake-3.22.2-windows-i386.zip
    Extracting cmake...
    The following packages will be built and installed:
      * angle[core]:x64-windows -> chromium_4472#2
      * brotli[core]:x64-windows -> 1.0.9#2
      * bzip2[core]:x64-windows -> 1.0.8#2
      * cairo[core,fontconfig,freetype,gobject]:x64-windows -> 1.17.4#4
      * dirent[core]:x64-windows -> 1.23.2#1
      * double-conversion[core]:x64-windows -> 3.2.0
      * egl-registry[core]:x64-windows -> 2021-11-23
      * expat[core]:x64-windows -> 2.4.1
      * fontconfig[core]:x64-windows -> 2.13.94#5
      * freeglut[core]:x64-windows -> 3.2.1#7
      * freetype[brotli,bzip2,core,png,zlib]:x64-windows -> 2.11.1
      * gettext[core]:x64-windows -> 0.21#9
      * glib[core]:x64-windows -> 2.70.1#2
      * graphene[core]:x64-windows -> 1.10.2#2
      * gstreamer[core,flac,gl-graphene,plugins-base,plugins-good,plugins-ugly,rawparse,x264]:x64-windows -> 1.19.2#5
      * harfbuzz[core]:x64-windows -> 3.2.0#1
      * hunspell[core]:x64-windows -> 1.7.0#8
      * icu[core]:x64-windows -> 69.1#18
      * jack2[core]:x64-windows -> 1.9.19#1
      * jasper[core,opengl]:x64-windows -> 2.0.33#3
      * json-c[core]:x64-windows -> 2019-09-10#2
      * lcms[core]:x64-windows -> 2.12#3
      * libarchive[bzip2,core,libxml2,lz4,lzma,openssl,zstd]:x64-windows -> 3.5.2#4
      * libffi[core]:x64-windows -> 3.4.2#4
      * libflac[core]:x64-windows -> 1.3.3#7
      * libiconv[core]:x64-windows -> 1.16#11
      * libjpeg-turbo[core]:x64-windows -> 2.1.3
      * liblzma[core]:x64-windows -> 5.2.5#5
      * libnice[core]:x64-windows -> 0.1.18
      * libogg[core]:x64-windows -> 1.3.5
      * libpng[core]:x64-windows -> 1.6.37#16
      * libpq[core,openssl,zlib]:x64-windows -> 12.9#1
      * libraw[core]:x64-windows -> 201903#7
      * libvpx[core]:x64-windows -> 1.10.0#2
      * libwebp[core,nearlossless,simd,unicode]:x64-windows -> 1.2.1
      * libxml2[core]:x64-windows -> 2.9.12#5
      * libyaml[core]:x64-windows -> 0.2.5#3
      * lz4[core]:x64-windows -> 1.9.3#3
      * lzo[core]:x64-windows -> 2.10#7
      * mpg123[core]:x64-windows -> 1.29.2#1
      * open62541[amalgamation,core,openssl]:x64-windows -> 1.2.3
      * opengl[core]:x64-windows -> 0.0#9
      * opengl-registry[core]:x64-windows -> 2021-11-17
      * openssl[core]:x64-windows -> 1.1.1m#2
      * pcre[core]:x64-windows -> 8.45#2
      * pcre2[core]:x64-windows -> 10.39#2
      * pixman[core]:x64-windows -> 0.40.0#2
      * pkgconf[core]:x64-windows -> 1.8.0#2
      * pthread[core]:x64-windows -> 3.0.0#1
      * pthreads[core]:x64-windows -> 3.0.0#10
        qt[core,default-features]:x64-windows -> 6.2.3
      * qt5compat[big-codecs,codecs,core,default-features,qml,textcodec]:x64-windows -> 6.2.3
      * qtactiveqt[core,qml]:x64-windows -> 6.2.3
      * qtapplicationmanager[core]:x64-windows -> 6.2.3
      * qtbase[brotli,concurrent,core,dbus,default-features,doubleconversion,freetype,gui,harfbuzz,icu,jpeg,network,openssl,pcre2,png,sql,sql-psql,sql-sqlite,testlib,widgets,zstd]:x64-windows -> 6.2.3
      * qtcharts[core,designer,qml]:x64-windows -> 6.2.3
      * qtcoap[core]:x64-windows -> 6.2.3
      * qtconnectivity[core]:x64-windows -> 6.2.3
      * qtdatavis3d[core]:x64-windows -> 6.2.3
      * qtdeclarative[core]:x64-windows -> 6.2.3
      * qtdoc[core]:x64-windows -> 6.2.3
      * qtimageformats[core,default-features,jasper,tiff,webp]:x64-windows -> 6.2.3
      * qtinterfaceframework[core]:x64-windows -> 6.2.3#1
      * qtlocation[core]:x64-windows -> 6.2.3
      * qtlottie[core,qml]:x64-windows -> 6.2.3
      * qtmqtt[core]:x64-windows -> 6.2.3
      * qtmultimedia[core,gstreamer,qml,widgets]:x64-windows -> 6.2.3
      * qtnetworkauth[core]:x64-windows -> 6.2.3
      * qtopcua[core,default-features,gds,ns0idnames,open62541,qml]:x64-windows -> 6.2.3
      * qtpositioning[core,qml]:x64-windows -> 6.2.3
      * qtquick3d[core,default-features]:x64-windows -> 6.2.3
      * qtquicktimeline[core]:x64-windows -> 6.2.3
      * qtremoteobjects[core,qml]:x64-windows -> 6.2.3
      * qtscxml[core,qml]:x64-windows -> 6.2.3
      * qtsensors[core,qml]:x64-windows -> 6.2.3
      * qtserialbus[core,default-features]:x64-windows -> 6.2.3
      * qtserialport[core]:x64-windows -> 6.2.3
      * qtshadertools[core]:x64-windows -> 6.2.3
      * qtsvg[core]:x64-windows -> 6.2.3
      * qttools[assistant,core,designer,linguist,qml]:x64-windows -> 6.2.3
      * qttranslations[core,default-features]:x64-windows -> 6.2.3
      * qtvirtualkeyboard[core,default-features,hunspell]:x64-windows -> 6.2.3
      * qtwebchannel[core,qml]:x64-windows -> 6.2.3
      * qtwebengine[core,default-features,geolocation,spellchecker,webchannel]:x64-windows -> 6.2.3
      * qtwebsockets[core,qml]:x64-windows -> 6.2.3
      * qtwebview[core,qml,webengine]:x64-windows -> 6.2.3
      * speex[core]:x64-windows -> 1.2.0#10
      * sqlite3[core]:x64-windows -> 3.37.2#1
      * taglib[core]:x64-windows -> 1.12.0#2
      * tiff[core,jpeg,lzma,zip]:x64-windows -> 4.3.0#6
      * vcpkg-cmake[core]:x64-windows -> 2022-01-19
      * vcpkg-cmake-config[core]:x64-windows -> 2022-02-06
      * vcpkg-tool-meson[core]:x64-windows -> 0.60.2#2
      * vcpkg-tool-nodejs[core]:x64-windows -> 14.17.4
      * x264[core]:x64-windows -> 164-5db6aa6cab1b146#4
      * yasm[core,tools]:x64-windows -> 1.3.0#3
      * yasm-tool-helper[core]:x64-windows -> 2020-03-11#1
      * zlib[core]:x64-windows -> 1.2.11#13
      * zstd[core]:x64-windows -> 1.5.2#1
    Additional packages (*) will be modified to complete this operation.
    Detecting compiler hash for triplet x64-windows...
    

    无奈,编译失败,卡在qtinterfaceframework这个了,好像和Python有点关系,建了一个Issue

    -- Using cached pypa-get-pip-309a56c5fd94bd1134053a541cb4657a4e47e09d.tar.gz.
    -- Cleaning sources at C:/v/buildtrees/qtinterfaceframework/src/7a4e47e09d-f4730c06c6.clean. Use --editable to skip cleaning for the packages you specify.
    -- Extracting source C:/v/downloads/pypa-get-pip-309a56c5fd94bd1134053a541cb4657a4e47e09d.tar.gz
    -- Using source at C:/v/buildtrees/qtinterfaceframework/src/7a4e47e09d-f4730c06c6.clean
    Collecting pip
    ERROR: Exception:
    Traceback (most recent call last):
      File "C:\Users\TAYLOR~1\AppData\Local\Temp\tmpmx23mo6d\pip.zip\pip\_internal\cli\base_command.py", line 188, in main
        status = self.run(options, args)
      File "C:\Users\TAYLOR~1\AppData\Local\Temp\tmpmx23mo6d\pip.zip\pip\_internal\commands\install.py", line 345, in run
        resolver.resolve(requirement_set)
      File "C:\Users\TAYLOR~1\AppData\Local\Temp\tmpmx23mo6d\pip.zip\pip\_internal\legacy_resolve.py", line 196, in resolve
        self._resolve_one(requirement_set, req)
      File "C:\Users\TAYLOR~1\AppData\Local\Temp\tmpmx23mo6d\pip.zip\pip\_internal\legacy_resolve.py", line 359, in _resolve_one
        abstract_dist = self._get_abstract_dist_for(req_to_install)
    

    他们建议我试试这个PR

    gh pr checkout 23089
    

    还是失败,暂时等待他们那个问题解决才能继续这个了。

    Vcpkg编译QT(5.15.3)

    vcpkg install qt5:x64-windows
    
    ❯ vcpkg install qt5:x64-windows
    Computing installation plan...
    The following packages will be built and installed:
        qt5[activeqt,core,declarative,essentials,imageformats,multimedia,networkauth,quickcontrols2,svg,tools]:x64-windows -> 5.15.3
      * qt5-multimedia[core]:x64-windows -> 5.15.3
      * qt5-networkauth[core]:x64-windows -> 5.15.3
    Additional packages (*) will be modified to complete this operation.
    Detecting compiler hash for triplet x64-windows...
    Restored 0 packages from C:\Users\TaylorShi\AppData\Local\vcpkg\archives in 595.7 us. Use --debug to see more details.
    Starting package 1/3: qt5-multimedia:x64-windows
    Building package qt5-multimedia[core]:x64-windows...
    -- Downloading https://download.qt.io/official_releases/qt/5.15/5.15.3/submodules/qtmultimedia-everywhere-opensource-src-5.15.3.tar.xz;https://mirrors.ocf.berkeley.edu/qt/official_releases/qt/5.15/5.15.3/submodules/qtmultimedia-everywhere-opensource-src-5.15.3.tar.xz -> qtmultimedia-everywhere-opensource-src-5.15.3.tar.xz...
    -- Extracting source C:/v/downloads/qtmultimedia-everywhere-opensource-src-5.15.3.tar.xz
    -- Using source at C:/v/buildtrees/qt5-multimedia/src/5.15.3-3689fd609c.clean
    -- Using cached msys-mingw-w64-i686-pkg-config-0.29.2-3-any.pkg.tar.zst.
    -- Using cached msys-mingw-w64-i686-libwinpthread-git-9.0.0.6373.5be8fcd83-1-any.pkg.tar.zst.
    -- Using msys root at C:/v/downloads/tools/msys2/9a1ec3f33446b195
    -- Configuring x64-windows-rel
    -- Configuring x64-windows-rel done
    -- Configuring x64-windows-dbg
    -- Configuring x64-windows-dbg done
    -- Package build-x64-windows-dbg
    

    得益于之前编译过qt5-webengine,已经把大部分依赖都解决了,剩下三个,于是很快就结束了。

    image

    我们试着导出一下吧。

    vcpkg export qt5:x64-windows --7zip
    

    然后我们将其重命名为qt-5.15.3-x64-windows-export-20220312-023757.7z

    image

    参考

  • 相关阅读:
    FZU 2098 刻苦的小芳(卡特兰数,动态规划)
    卡特兰数总结
    FZU 1064 教授的测试(卡特兰数,递归)
    HDU 4745 Two Rabbits(区间DP,最长非连续回文子串)
    Java 第十一届 蓝桥杯 省模拟赛 正整数的摆动序列
    Java 第十一届 蓝桥杯 省模拟赛 反倍数
    Java 第十一届 蓝桥杯 省模拟赛 反倍数
    Java 第十一届 蓝桥杯 省模拟赛 反倍数
    Java 第十一届 蓝桥杯 省模拟赛 凯撒密码加密
    Java 第十一届 蓝桥杯 省模拟赛 凯撒密码加密
  • 原文地址:https://www.cnblogs.com/taylorshi/p/15976332.html
Copyright © 2020-2023  润新知