快速開始 - Windows


 首先,下載vcpkg,它可以安裝在任何地方,但是通常我們建議您使用 vcpkg 作為 CMake 項目的子模塊,並將其全局安裝到 Visual Studio 項目中。我們建議您使用如 D:\src\vcpkg 或 D:\dev\vcpkg 的安裝目錄,否則在安裝某些庫時,您可能遇到路徑問題或權限問題。

Windows PowerShell

Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6 PS D:\> git clone https://github.com/microsoft/vcpkg.git Cloning into 'vcpkg'... remote: Enumerating objects: 14, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (13/13), done. remote: Total 104557 (delta 2), reused 4 (delta 1), pack-reused 104543 Receiving objects: 100% (104557/104557), 31.73 MiB | 32.10 MiB/s, done. Resolving deltas: 100% (65552/65552), done. Updating files: 100% (7280/7280), done. PS D:\>

 

進入克隆的vcpkg目錄中, 請使用powershell執行bootstrap-vcpkg.bat腳本下載已簽名的vcpkg二進制文件。

注意:使用cmd命令行,Visual Studio命令行或其他命令行執行vcpkg命令可能導致編譯過程中腳本調用錯誤或其他問題,所以我們推薦使用powershell。

 

PS D:\vcpkg> .\bootstrap-vcpkg.bat

Downloading https://github.com/microsoft/vcpkg-tool/releases/download/2021-02-24-d67989bce1043b98092ac45996a8230a059a2d7e/vcpkg.exe -> D:\vcpkg/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 PS D:\vcpkg>

 

若不想讓vcpkg上傳遙測數據(僅用於改善vcpkg),請在bootstrap-vcpkg.bat腳本后添加命令-disableMetrics。

至此,我們已經准備好安裝vcpkg支持的第三方庫了。對於一些編譯過程中需要的工具,則會在首次安裝庫時自動下載。

示例:安裝zlib

.\vcpkg.exe install zlib

輸出信息:

PS D:\vcpkg> .\vcpkg.exe install zlib

Computing installation plan...
A suitable version of cmake was not found (required v3.19.2). Downloading portable cmake v3.19.2... Downloading cmake... https://github.com/Kitware/CMake/releases/download/v3.19.2/cmake-3.19.2-win32-x86.zip -> D:\vcpkg\downloads\cmake-3.19.2-win32-x86.zip Extracting cmake... A suitable version of 7zip was not found (required v18.1.0). Downloading portable 7zip v18.1.0... Downloading 7zip... https://www.nuget.org/api/v2/package/7-Zip.CommandLine/18.1.0 -> D:\vcpkg\downloads\7-zip.commandline.18.1.0.nupkg Extracting 7zip... A suitable version of nuget was not found (required v5.5.1). Downloading portable nuget v5.5.1... Downloading nuget... https://dist.nuget.org/win-x86-commandline/v5.5.1/nuget.exe -> D:\vcpkg\downloads\22ea847d-nuget.exe The following packages will be built and installed: zlib[core]:x86-windows -> 1.2.11#9  Detecting compiler hash for triplet x86-windows... A suitable version of git was not found (required v2.26.2). Downloading portable git v2.26.2... Downloading git... https://github.com/git-for-windows/git/releases/download/v2.26.2.windows.1/PortableGit-2.26.2-32-bit.7z.exe -> D:\vcpkg\downloads\PortableGit-2.26.2-32-bit.7z.exe Extracting git... A suitable version of powershell-core was not found (required v7.1.0). Downloading portable powershell-core v7.1.0... Downloading powershell-core... https://github.com/PowerShell/PowerShell/releases/download/v7.1.0/PowerShell-7.1.0-win-x86.zip -> D:\vcpkg\downloads\PowerShell-7.1.0-win-x86.zip Extracting powershell-core... Using cached binary package: C:\Users\jack\AppData\Local\vcpkg\archives\36\361ee62e74ca723768c8504c31a2a806c00294fa.zip Starting package 1/1: zlib:x86-windows Building package zlib[core]:x86-windows... Building package zlib[core]:x86-windows... done Installing package zlib[core]:x86-windows... Installing package zlib[core]:x86-windows... done Elapsed time for package zlib:x86-windows: 135.9 ms Total elapsed time: 20.34 s The package zlib is compatible with built-in CMake targets: find_package(ZLIB REQUIRED) target_link_libraries(main PRIVATE ZLIB::ZLIB) PS D:\vcpkg>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM