将下列powershell
代码存成ps1
文件,在目录下shift
右键->打开power shell
窗口,运行脚本后vcpkg
即安装完成。
# 1. 创建目录、下载vcpkg:
mkdir -f D:/APPs
cd D:/APPs
# github
# git clone https://github.com/microsoft/vcpkg
# gitee
git clone https://gitee.com/mirrors/vcpkg.git
# 2. 安装:运行vcpkg目录下的 bootstrap-vcpkg.bat
cd vcpkg
./bootstrap-vcpkg.bat
# 3. 添加环境变量
setx VCPKG_ROOT $pwd
将
D:/APPs
改为自己想要安装的位置~
如果要在Visual Studio
工程中使用vcpkg
,需要运行:
vcpkg integrate install
☀️☀️☀️这样的话,在VS
的非CMake工程中可以直接#include
来引用已安装的库,不需要配置include/lib/dll
文件。
这功能简直太了!
建议使用vcpkg的话,直接创建
VS
工程,特别省心。
如果在VS
的CMake工程中使用,则需要打开CMake
设置选项,将 vcpkg toolchain
文件路径设置赋值给 CMAKE_TOOLCHAIN_FILE
。
CMAKE_TOOLCHAIN_FILE
是一个命令行参数,通过在执行cmake
命令时提供-DCMAKE_TOOLCHAIN_FILE=xxxPath
,也可以在CMakeLists.txt
中如下设置:
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake")
可以参考官方文档:CMAKE_TOOLCHAIN_FILE
官方:将以下内容添加到 settings.json
中将使CMake Tools
自动使用vcpkg
中的第三方库:
{
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE": "[vcpkg root]/scripts/buildsystems/vcpkg.cmake"
}
}
可以使用
Ctrl+Shift+P
输入settings.json
打开设置,然后添加上述内容,记得将[vcpkg root]
换成自己的vcpkg.exe
所在目录。
但是实际使用遇到的问题不少,有需要再单独研究记录一下~
个人比较想实现
windows+minGW+vcpkg
的路线,总不太能❌如意……
vcpkg
安装依赖库的语法为:
# 默认安装x86版本
vcpkg install libhv
# 安装x64版本
vcpkg install libhv:x64-windows
# 或者这样安装x64版本
vcpkg install libhv --triplet=x64-windows
可以使用 search
子命令来查找vcpkg
中集成的库,将给出所有相关结果:
PS E:\APPs> vcpkg search hv
gazebo[graphviz] Enable model editor's schematic view
graphviz 2.49.1#2 Graph Visualization Tools
libhv 1.2.4#1 Libhv is a C/C++ network library similar to libevent/libuv.
libhv[ssl] with openssl library
libssh 0.9.6#2 libssh is a multiplatform C library implementing the SSHv2 protocol on cli...
libssh[crypto] Default crypto backend
libssh[mbedtls] Crypto support (mbedTLS)
libssh[openssl] Crypto support (OpenSSL)
libssh[zlib] libssh with zlib
The result may be outdated. Run `git pull` to get the latest results.
If your port is not listed, please open an issue at and/or consider making a pull request:
https://github.com/Microsoft/vcpkg/issues
如有错误 ❌ ,欢迎指正 ☝️~
如有收获 ,点赞/评论/收藏⭐️/关注~