原文:https://www.136.la/shida/show-3367.html
https://vcpkg.io/en/getting-started.html
-------------------------------
簡介 這篇文章主要介紹了win10 + vs2017 + vcpkg —— VC++ 打包工具(示例代碼)以及相關的經驗技巧,文章約4788字,瀏覽量273,點贊數8,值得推薦!
vcpkg 是微軟 C++ 團隊開發的在 Windows 上運行的 C/C++ 項目包管理工具,可以幫助您在 Windows 平臺上獲取 C 和 C++ 庫.
vcpkg 自身也是使用 C++ 開發的 (而其他的 C++ 包管理大多並不是 C++ 開發的),並且 vcpkg 能夠幫助用戶在 Visual Studio 中,更好的使用這些安裝好的庫.
vcpkg 整合了 git,構建系統整合的 CMake,而絕大多數的 C++ 項目都可以直接或者間接的方式使用 CMake創建原生項目文件並構建.
安裝:
git clone https://github.com/Microsoft/vcpkg
cd vcpkg
powershell -exec bypass scripts\bootstrap.ps1
設置環境變量
默認編譯庫類型(32位還是64位) VCPKG_DEFAULT_TRIPLET, 可設置的值如下:
PS > ./vcpkg help triplet
Available architecture triplets:
arm-uwp
x64-uwp
x64-windows-static
x64-windows
x86-uwp
x86-windows-static
x86-windows
vcpkg命令
打開Windows PowerShell
查看幫助
./vcpkg --help
Commands:
vcpkg search [pat] 查找包 Search for packages available to be built
vcpkg install <pkg> 安裝包 Install a package
vcpkg remove <pkg> 卸載包 Uninstall a package.
vcpkg remove --purge <pkg> 卸載並刪除包(包升級時需要) Uninstall and delete a package.
vcpkg list 列出已安裝包 List installed packages
vcpkg update 列出需要升級的包 Display list of packages for updating
vcpkg hash <file> [alg] 對文件進行Hash(默認是SHA512) Hash a file by specific algorithm, default SHA512
vcpkg integrate install Make installed packages available user-wide. Requires admin privileges on first use
vcpkg integrate remove Remove user-wide integration
vcpkg integrate project Generate a referencing nuget package for individual VS project use
vcpkg edit <pkg> Open up a port for editing (uses %EDITOR%, default ‘code‘)
vcpkg import <pkg> Import a pre-built library
vcpkg create <pkg> <url>
[archivename] Create a new package
vcpkg owns <pat> Search for files in installed packages
vcpkg cache List cached compiled packages
vcpkg version Display version information
vcpkg contact Display contact information to send feedback
Options:
--triplet <t> Specify the target architecture triplet.
(default: %VCPKG_DEFAULT_TRIPLET%, see ‘vcpkg help triplet‘)
--vcpkg-root <path> Specify the vcpkg root directory
(default: %VCPKG_ROOT%)
示例:
刪除庫(VCPKG_DEFAULT_TRIPLET指定位)
./vcpkg remove zlib libiconv
刪除32位庫
./vcpkg remove zlib:x86-windows libiconv:x86-windows
刪除64位庫
./vcpkg remove zlib:x64-windows libiconv:x64-windows
---------------------------------------------------------------------------------------------------------------------
微軟官方:https://vcpkg.io/en/getting-started.html
Installing vcpkg is a two-step process: first, clone the repo, then run the bootstrapping script to produce the vcpkg binary. The repo can be cloned anywhere, and will include the vcpkg binary after bootstrapping as well as any libraries that are installed from the command line. It is recommended to clone vcpkg as a submodule for CMake projects, but to install it globally for MSBuild projects. If installing globally, we recommend a short install path like: C:\src\vcpkg or C:\dev\vcpkg, since otherwise you may run into path issues for some port build systems.
Step 1: Clone the vcpkg repo
git clone https://github.com/Microsoft/vcpkg.git
Make sure you are in the directory you want the tool installed to before doing this.
Step 2: Run the bootstrap script to build vcpkg
.\vcpkg\bootstrap-vcpkg.bat
vcpkg install [packages to install]
vcpkg integrate install
After this, you can create a new project or open an existing one in the IDE. All installed libraries should already be discoverable by IntelliSense and usable in code without additional configuration.
cmake -B [build directory] -S . -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake
Then build with:
cmake --build [build directory]
With CMake, you will need to use find_package() to reference the libraries in your Cmakelists.txt files.