跳转至

vcpkg

vcpkg is a free C/C++ package manager for acquiring and managing libraries. Choose from over 1500 open source libraries to download and build in a single step or add your own private libraries to simplify your build process. Maintained by the Microsoft C++ team and open source contributors.

article link

Set up vcpkg

1、Clone the repository

Text Only
1
2
3
4
5
6
7
8
9
PS C:\dev> git clone https://github.com/microsoft/vcpkg.git
Cloning into 'vcpkg'...
remote: Enumerating objects: 245363, done.
remote: Counting objects: 100% (22102/22102), done.
remote: Compressing objects: 100% (378/378), done.
remote: Total 245363 (delta 21931), reused 21736 (delta 21724), pack-reused 223261 (from 1)Receiving objects: 100% (2453Receiving objects: 100% (245363/245363), 72.53 MiB | 4.07 MiB/s, done.

Resolving deltas: 100% (164093/164093), done.
Updating files: 100% (11632/11632), done.

2、Run the bootstrap script

Text Only
1
cd vcpkg && bootstrap-vcpkg.bat

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
PS C:\dev\vcpkg> ./bootstrap-vcpkg.bat
Downloading https://github.com/microsoft/vcpkg-tool/releases/download/2024-08-01/vcpkg.exe -> C:\dev\vcpkg\vcpkg.exe (using IE proxy: 127.0.0.1:10809)... done.
Validating signature... done.

vcpkg package management program version 2024-08-01-fd884a0d390d12783076341bd43d77c3a6a15658

See LICENSE.txt for license information.
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

update

Text Only
1
2
3
  .\vcpkg.exe update
  .\vcpkg.exe upgrade
  .\vcpkg.exe upgrade --no-dry-run

git pull

Text Only
1
2
  PS C:\dev\vcpkg> .\vcpkg.exe update
  Using local portfile versions. To update the local portfiles, use `git pull`.

update example

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  PS C:\dev\vcpkg> .\vcpkg.exe update
  Using local portfile versions. To update the local portfiles, use `git pull`.
  The following packages differ from their port versions:
          angle:x64-windows                chromium_5414#4 -> chromium_5414#7
          assimp:x64-windows               5.2.5 -> 5.3.1#3
          eigen3:x64-windows               3.4.0#2 -> 3.4.0#3
          kubazip:x64-windows              0.2.4 -> 0.2.6
          minizip:x64-windows              1.2.13#2 -> 1.3#1
          pugixml:x64-windows              1.13.0 -> 1.14
          rapidjson:x64-windows            2023-04-27 -> 2023-07-17
          utfcpp:x64-windows               3.2.3 -> 4.0.2
          vcpkg-get-python-packages:x64-windows 2022-06-30 -> 2023-07-28
          zlib:x64-windows                 1.2.13 -> 1.3  

upgrade

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
  PS C:\dev\vcpkg> .\vcpkg.exe upgrade
  The following packages will be rebuilt:
    * angle:x64-windows -> chromium_5414#7
    * assimp:x64-windows -> 5.3.1#3
    * eigen3:x64-windows -> 3.4.0#3
    * kubazip:x64-windows -> 0.2.6
    * minizip:x64-windows -> 1.3#1
    * pugixml:x64-windows -> 1.14
    * rapidjson:x64-windows -> 2023-07-17
    * utfcpp:x64-windows -> 4.0.2
    * vcpkg-get-python-packages:x64-windows -> 2023-07-28
    * zlib:x64-windows -> 1.3
  The following packages will be built and installed:
    * polyclipping:x64-windows -> 6.4.2#12
    * vcpkg-cmake-get-vars:x64-windows -> 2023-03-02
  Additional packages (*) will be modified to complete this operation.
  If you are sure you want to rebuild the above packages, run this command with the --no-dry-run option.          
Text Only
1
2
  .\vcpkg.exe search poly2tri
  .\vcpkg.exe search eigen

remove

Text Only
1
2
  .\vcpkg.exe remove --outdated
  .\vcpkg.exe remove --outdated --recurse

list

Text Only
1
  .\vcpkg.exe list  

install

Text Only
1
  .\vcpkg.exe install eigen3

cmake

Text Only
1
  cmake -DCMAKE_TOOLCHAIN_FILE="C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake" ..  

error info

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
PS C:\dev\vcpkg> .\vcpkg.exe install eigen3
Computing installation plan...
The following packages will be built and installed:
    eigen3:x64-windows -> 3.4.0#4
  * vcpkg-cmake:x64-windows -> 2024-04-23
  * vcpkg-cmake-config:x64-windows -> 2024-05-23
Additional packages (*) will be modified to complete this operation.
error: in triplet x64-windows: Unable to find a valid Visual Studio instance
Could not locate a complete Visual Studio instance
The following paths were examined for Visual Studio instances:
    C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary/Build\vcvarsall.bat

example

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
cmake_minimum_required(VERSION 3.0)
project(YourProjectName)

# 设置vcpkg的路径
set(VCPKG_ROOT "path/to/vcpkg" CACHE STRING "Vcpkg root directory")

# 设置vcpkg的三个变量
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "Vcpkg target triplet")
set(VCPKG_OVERLAY_PORTS "path/to/your/overlay/ports" CACHE STRING "Vcpkg overlay ports directory")

# 添加vcpkg的库
find_package(vcpkg_library_name REQUIRED)

# 添加你的库
add_library(YourLibraryName SHARED YourSourceFiles)

# 链接vcpkg的库到你的库
target_link_libraries(YourLibraryName PRIVATE vcpkg_library_name)