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

Step 2: Run the bootstrap script to build vcpkg

./vcpkg\bootstrap-vcpkg.bat

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 # 移除过时的包

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

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

更新

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

export

有的时候,一个项目组中有很多人,不需要每个人都参与编译。一个人编译好所有开源库后到处给别人即可。有的时候也是出于备份的目的,也会导出已经安装的开源库。导出可以执行export指令。例如,我要导出jsoncpp库,那么执行:

.\vcpkg.exe export openssl:x64-windows --7zip
 
注意,导出时必须指定导出的包格式。vcpkg支持5种导出包格式,有:
参数          格式
–raw            以不打包的目录格式导出
–nuget  以nuget包形式导出
–ifw            我也不知道这是啥格式
–zip            以zip压缩包形式导出
–7zip   以7z压缩包形式导出 

几个重要目录

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中恢复。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值