• vcpkg 简明教程


    vcpkg 简明教程

    Refer

    vcpkg getstarted:https://vcpkg.io/en/getting-started.html

    vcpkg支持的库:https://vcpkg.io/en/packages.html

    vcpkg中文快速入门: https://www.cnblogs.com/flyinggod/p/10786243.html

    Install vcpkg

    Step 1: Clone the vcpkg repo

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

    Step 2: Run the bootstrap script to build vcpkg

    ./vcpkg\bootstrap-vcpkg.bat
    
    • 1

    Commands

    openssl 库为例

    ./vcpkg.exe search openssl # 查找目标库
    ./vcpkg.exe help triplet # 查看支持的arch
    ./vcpkg install openssl:x64-windows # 安装目标库
    ./vcpkg list # 查看已经安装的库
    ./vcpkg.exe export openssl:x64-windows --zip
    ./vcpkg.exe remove openssl:x64-windows # 移除目标库
    ./vcpkg.exe remove --outdated # 移除过时的包
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    triplet

    ./vcpkg.exe help triplet
    Available architecture triplets:
    vcpkg built-in triplets:
      arm-uwp
      arm64-windows
      x64-linux
      x64-osx
      x64-uwp
      x64-windows-static
      x64-windows
      x86-windows
    VCPKG community triplets:
      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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54

    install

    vcpkg install openssl
    安装过程分为如下过程 
    1.环境初始化
    2.下载源代码(downloads 目录,如果已存在,则不下载)
    3.校验文件有效性
    4.解压缩源代码
    5.利用配套工具配置源码工程,在这里是使用的是cmake(如果是ffmpeg,则用msys2)
    7.编译源码。一般会同时编译Release和Debug版本。
    8.把编译好的文件拷贝到相关目录中去(一般是installed目录)
     
    注意点:
    如果电脑中没有安装cmake,vcpkg会自动下载portable版本的cmake。但是由于各种原因,下载的网速很慢,所以建议先自行下载安装msi版本的cmake。最好是下载最新版本的cmake
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    更新

    一般有两种更新方式。一个是update指令,可以显示可以升级的开源库的列表。另一个是upgrade的指令,会重新编译所有需要更新的包。

    export

    有的时候,一个项目组中有很多人,不需要每个人都参与编译。一个人编译好所有开源库后到处给别人即可。有的时候也是出于备份的目的,也会导出已经安装的开源库。导出可以执行export指令。例如,我要导出jsoncpp库,那么执行:
    
    .\vcpkg.exe export openssl:x64-windows --7zip
     
    注意,导出时必须指定导出的包格式。vcpkg支持5种导出包格式,有:
    参数          格式
    –raw            以不打包的目录格式导出
    –nuget  以nuget包形式导出
    –ifw            我也不知道这是啥格式
    –zip            以zip压缩包形式导出
    –7zip   以7z压缩包形式导出 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    几个重要目录

    downloads :下载下来的库源文件

    ports:库的描述信息和编译信息,包括库的名字,版本,源文件来源等。

    buildtrees:库的源文件会被copy到这个目录下进行编译。

    位于buildtrees目录下,当install完成一个lib的时候,打开库目录下的CMakeCache.txt,可以看到类似CMAKE_CXX_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29333/bin/HostX64/x64/cl.exe的宏,从中可以看到编译的时候使用的编译器。

    installed:编译好的库会copy到这个目录

    packages:不知道有什么作用,看起来跟installed重复。

    C:\Users\admin\AppData\Local\vcpkg\archives
    build的cache,比如执行 ./vcpkg.exe remove zlib:x64-windows 以后再执行 ./vcpkg.exe install zlib:x64-windows 可能就不会重新编译一遍了,而直接从cache中恢复。

  • 相关阅读:
    团队协作:如何利用 Gitee 实现多人合作项目的版本控制
    基于阶梯碳交易的含P2G-CCS耦合和燃气掺氢的虚拟电厂优化调度(matlab代码)
    java计算机毕业设计智慧物业管理系统源程序+mysql+系统+lw文档+远程调试
    正点原子嵌入式linux驱动开发——Linux I2C驱动
    【论文导读】(AAAI)Achieving Counterfactual Fairness for Causal Bandit
    pytorch与keras的相互转换(代码以LeNet-5为例)
    再来看一个升级的案例
    FFmpeg入门详解之69:ffmpeg.c(4.3.1)源码剖析
    【20221114】【每日一题】复原IP地址
    小米云原生文件存储平台化实践:支撑 AI 训练、大模型、容器平台多项业务
  • 原文地址:https://blog.csdn.net/poinsettia/article/details/127885576