原文链接,不定时更新
「vcpkg」 微软 C++ 团队开发的在 Windows 上运行的 C/C++ 项目包管理工具,可以帮助您在 Windows 平台上获取 C 和 C++ 库
Vcpkg大量使用的psl脚本,所以官方强烈推荐使用PowerShell而不时CMD命令行来执行各种操作
查看帮助:vcpkg --help
.\vcpkg.exe remove --outdated #一键移除过时的包
.\vcpkg.exe list #列出已安装的包
使用须知:
PS D:\local\vcpkg> .\bootstrap-vcpkg.bat
Building vcpkg.exe ...
pch.cpp
archives.cpp
checks.cpp
chrono.cpp
cofffilereader.cpp
downloads.cpp
enums.cpp
files.cpp
hash.cpp
json.cpp
machinetype.cpp
parse.cpp
strings.cpp
stringview.cpp
system.cpp
system.print.cpp
system.process.cpp
unicode.cpp
binarycaching.cpp
binaryparagraph.cpp
build.cpp
buildenvironment.cpp
cmakevars.cpp
commands.autocomplete.cpp
commands.buildexternal.cpp
commands.cache.cpp
commands.ci.cpp
commands.ciclean.cpp
commands.contact.cpp
commands.cpp
commands.create.cpp
commands.dependinfo.cpp
commands.edit.cpp
commands.env.cpp
commands.exportifw.cpp
commands.format-manifest.cpp
commands.integrate.cpp
commands.list.cpp
commands.owns.cpp
commands.porthistory.cpp
commands.portsdiff.cpp
commands.search.cpp
commands.setinstalled.cpp
commands.upgrade.cpp
commands.version.cpp
commands.xvsinstances.cpp
dependencies.cpp
export.cpp
export.chocolatey.cpp
export.prefab.cpp
d:\local\vcpkg\toolsrc\src\vcpkg\export.prefab.cpp(1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据
丢失 [D:\local\vcpkg\toolsrc\vcpkglib\vcpkglib.vcxproj]
globalstate.cpp
help.cpp
input.cpp
install.cpp
platform-expression.cpp
metrics.cpp
packagespec.cpp
paragraphparseresult.cpp
paragraphs.cpp
portfileprovider.cpp
postbuildlint.buildtype.cpp
postbuildlint.cpp
remove.cpp
sourceparagraph.cpp
statusparagraph.cpp
statusparagraphs.cpp
tools.cpp
triplet.cpp
update.cpp
userconfig.cpp
vcpkgcmdarguments.cpp
vcpkglib.cpp
vcpkgpaths.cpp
versiont.cpp
visualstudio.cpp
vcpkglib.vcxproj -> D:\local\vcpkg\toolsrc\msbuild.x86.release\vcpkglib.lib
vcpkg.cpp
正在生成代码
All 23072 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
已完成代码的生成
vcpkg.vcxproj -> D:\local\vcpkg\toolsrc\msbuild.x86.release\vcpkg.exe
vcpkgmetricsuploader.cpp
正在生成代码
All 9688 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
已完成代码的生成
vcpkgmetricsuploader.vcxproj -> D:\local\vcpkg\toolsrc\msbuild.x86.release\vcpkgmetricsuploader.exe
Building vcpkg.exe... done.
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
只需列出Vckpg所支持的开源库列表,并找到对应的库名称,运行命令安装即可\
.\vcpkg.exe search
.\vcpkg.exe install jsoncpp
我们大致可以了解到install会经历这几个过程:
注意点:如果电脑中没有安装cmake,vcpkg会自动下载portable版本的cmake。但是由于各种原因,下载的网速很慢,所以建议先自行下载安装msi版本的cmake。最好是下载最新版本的cmake。
Vcpkg默认把开源库编译成Windows x86的版本,有两种方式指定版本:
VCPKG_DEFAULT_TRIPLET = x64-windows
./vcpkg.exe install cgal:x64-windows
Vcpkg一共支持以下系统,可以使用.\vcpkg.exe help triplet
查看
• arm-uwp
、arm64-uwp
• arm-windows
、arm64-windows
• x86-uwp、x64-uwp
• x86-windows
、x86-windows-static
• x64-windows
、x64-windows-static
Note:需要非常注意的是,在使用Vcpkg时,有涉及到平台版本的时候,缺省值都是windows x86。为了避免不必要的麻烦,建议每次都以后缀形式指定版本
移除一个已经安装的开源库:
.\vcpkg.exe remove jsoncpp
需要注意的是:
无论是因为共享,还是备份,我们都可能需要导出已安装的库。
.\vcpkg.exe export jsoncpp --7zip
.\vcpkg.exe import xxx.7z
设置环境变量的文件路径:{VCPKG_ROOT}\triplets\x64-windows.cmake
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_PLATFORM_TOOLSET v140)
如何使用Vcpkg安装的包?
「集成」:我们把使用库这个过程称之为集成
“集成到全局”适用于Visual Studio开发环境和msbuild命令行
PS D:\local\vcpkg> .\vcpkg.exe integrate install
Applied user-wide integration for this vcpkg root.
All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=D:/local/vcpkg/scripts/buildsystems/vcpkg.cmake"
移除全局:
PS D:\local\vcpkg> .\vcpkg.exe integrate remove
User-wide integration was removed
“集成到工程”是整个vcpkg中最复杂的一项,它需要利用Visual Studio 中的nuget插件来实现
(1)在Vcpkg中生成NuGet配置文件
.\vcpkg integrate project #在
(2)在NuGet中添加源
(3)工程设置
在cmake中集成只要在cmake文件中加入下面这句话即可。
-DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake"
Vcpkg默认编译链接的是动态库,如果要链接静态库,目前还没有简便的方法。需要做如下操作
<VcpkgTriplet>x86-windows-staticVcpkgTriplet>
<VcpkgEnabled>trueVcpkgEnabled>
在CMake中集成静态库,需要额外指令
cmake .. -DCMAKE_TOOLCHAIN_FILE=.../vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x86-windows-static
解决方案:手动下载文件,并存在download文件夹中, 重命名成temp里的文件名
参考链接
Additional packages (*) will be modified to complete this operation.
Warning: The following VS instances are excluded because the English language pack is unavailable.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
Please install the English language pack.