1. 程式人生 > 其它 >【轉】win10 + vs2017 + vcpkg —— VC++ 打包工具(示例程式碼)

【轉】win10 + vs2017 + vcpkg —— VC++ 打包工具(示例程式碼)

原文: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

Install vcpkg

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\vcpkgorC:\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

Install libraries for your project

vcpkg install [packages to install]

Using vcpkg with MSBuild / Visual Studio (may require elevation)

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.

Using vcpkg with CMake In order to use vcpkg with CMake outside of an IDE, you can use the toolchain file:

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 usefind_package()to reference the libraries in your Cmakelists.txt files.

Browse thevcpkg documentationto learn more about how to enable different workflows.