Abel'Blog

我干了什么?究竟拿了时间换了什么?

0%

vcpkg-c++包管理

概述

vcpkg 是一个 C++ 包管理器,用于 Windows、Linux 和 macOS。它由 Microsoft 维护,并支持大量的 C++ 库。使用 vcpkg,你可以轻松地安装、升级和管理 C++ 依赖库。

实践

安装 vcpkg

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

./bootstrap-vcpkg.sh
./vcpkg —version
vcpkg package management program version 2024-04-23-d6945642ee5c3076addd1a42c331bbf4cfc97457

See LICENSE.txt for license information.

vcpkg integrate bash
Adding vcpkg completion entry to /home/abel/.bashrc.

将目录增加到 PATH 里面方便运行。

尝试基本操作

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

vcpkg search boost

vcpkg
usage: vcpkg <command> [--switches] [--options=values] [arguments] @response_file
@response_file Contains one argument per line expanded at that location

Package Installation:
export Creates a standalone deployment of installed ports
install Installs a package
remove Uninstalls a package
x-set-installed Installs, upgrades, or removes packages such that that installed matches
exactly those supplied
upgrade Rebuilds all outdated packages

Package Discovery:
x-check-support Tests whether a port is supported without building it
depend-info Displays a list of dependencies for ports
list Lists installed libraries
owns Searches for the owner of a file in installed packages
x-package-info Display detailed information on packages
portsdiff Diffs changes in port versions between commits
search Searches for packages available to be built
update Lists packages that can be upgraded

Package Manipulation:
add Adds dependency to manifest
x-add-version Adds a version to the version database
create Creates a new port
edit Edits a port, optionally with $EDITOR, defaults to "code"
env Creates a clean shell environment for development or compiling
format-manifest Prettyfies vcpkg.json
hash Gets a file's SHA256 or SHA512
x-init-registry Creates a blank git registry
new Creates a new manifest
x-update-baseline Updates baselines of git registries in a manifest to those registries' HEAD
commit

Other:
ci Tries building all ports for CI testing
x-ci-verify-versions Checks integrity of the version database
contact Displays contact information to send feedback
fetch Fetches something from the system or the internet
integrate Integrates vcpkg with machines, projects, or shells

For More Help:
help topics Displays full list of help topics
help <topic> Displays specific help topic
help commands Displays full list of commands, including rare ones not listed here
help <command> Displays help detail for <command>

For more help (including examples) see https://learn.microsoft.com/vcpkg

build

1
2
3
4
# 设置好 VCPKG_ROOT 环境变量
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
# 当找不到 cmake 文件的时候,可以直接去目录里面搜索一下 *.cmake ,就能解决问题了
${VCPKG_ROOT}/packages/boost-test_xxx/

不要去使用,因为没有用。

1
2
set(CMAKE_TOOLCHAIN_FILE "/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")

引用