好好爱自己!

【转】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\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

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

Browse the vcpkg documentation to learn more about how to enable different workflows.
posted @ 2021-11-04 10:44  立志做一个好的程序员  阅读(601)  评论(0编辑  收藏  举报

不断学习创作,与自己快乐相处