手把手制作一个vcpkg的安装包及port file相关说明

0. 前言

Windows平台的程序包的依赖管理一直以来都是个大难题。之前有NuGet,现在有vcpkg
本文的重点是先介绍一下vcpkg的特性,然后以一个实际例子说明,说明如何创建一个vcpkg安装包。

1. vcpkg简介

vcpkg是为了在windows平台能够方便获取一个C或者C++库。当前还处于预览版状态。不过已经有很多常见的库了,例如:

  • openssl
  • boost
  • zlib
  • glog
  • libevent
  • curl

等等,很多知名的C/C++库都已经提供vcpkg安装包。

2. vcpkg安装

首先,我们的windows系统必须安装有下列软件

  • Visual Studio 2015 Update 3 or
  • Visual Studio 2017
  • CMake 3.8.0 or higher (note: downloaded automatically if not found)
  • git.exe available in your path

然后,我们在windows命令行终端上运行:

d:\git> git clone https://github.com/Microsoft/vcpkg
d:\git> cd vcpkg
d:\git\vcpkg> .\bootstrap-vcpkg.bat
d:\git\vcpkg> .\vcpkg integrate install

3. 使用vcpkg获取C/C++库

使用vcpkg --help命令查看联席帮助文档:

D:\git\vcpkg>.\vcpkg --help
Commands:
  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 hash <file> [alg]         Hash a file by specific algorithm, default SHA512

  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 export <pkg>... [opt]...  Exports a package
  vcpkg edit <pkg>                Open up a port for editing (uses %EDITOR%, default 'code')
  vcpkg import <pkg>              Import a pre-built library
  vcpkg create <pkg> <url>
             [archivename]        Create a new package
  vcpkg owns <pat>                Search for files in installed packages
  vcpkg cache                     List cached compiled packages
  vcpkg version                   Display version information
  vcpkg contact                   Display contact information to send feedback

Options:
  --triplet <t>                   Specify the target architecture triplet.
                                  (default: %VCPKG_DEFAULT_TRIPLET%, see 'vcpkg help triplet')

  --vcpkg-root <path>             Specify the vcpkg root directory
                                  (default: %VCPKG_ROOT%)

For more help (including examples) see the accompanying README.md.

这里我们可以看到,很多有用的命令

  • vcpkg search [pattern]
    • 搜索一个C/C++库
  • vcpkg install [pkg]
    • 安装一个C/C++库
  • vcpkg remove [pkg]
    • 卸载(删除)一个C/C++库

下面举例,安装curl这个常用的C语言写的网络库。

D:\git\vcpkg>.\vcpkg install curl
The following packages will be built and installed:
    curl:x86-windows
  * libssh2:x86-windows
Additional packages (*) will be installed to complete this operation.
Building package libssh2:x86-windows...
-- CURRENT_INSTALLED_DIR=D:/git/vcpkg/installed/x86-windows
-- DOWNLOADS=D:/git/vcpkg/downloads
-- CURRENT_PACKAGES_DIR=D:/git/vcpkg/packages/libssh2_x86-windows
-- CURRENT_BUILDTREES_DIR=D:/git/vcpkg/buildtrees/libssh2
-- CURRENT_PORT_DIR=D:/git/vcpkg/ports/libssh2/.
-- Downloading https://www.libssh2
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值