vcpkg工具+vs2019

本文介绍了vcpkg库管理工具,它简化了项目对第三方库的依赖处理,自动链接和安装,适用于C++项目。只需几步操作,即可全局集成并轻松使用各种库,如jsoncpp。适合开发者快速上手和项目管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

好处

自动处理库依赖, 不需额外配置库 include路径 和库 lib路径

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=F:/GIT/vcpkg/scripts/buildsystems/vcpkg.cmake"

在这里插入图片描述

安装

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat
vcpkg integrate install

//安装jsoncpp 32位库 可省略冒号后内容
vcpkg install jsoncpp 或vcpkg install jsoncpp:x86-windows 

//安装jsoncpp detours位库
vcpkg install detours:x64-windows //安装

//如果想在任意位置使用vcpkg 请把 vcpkg.exe 路径加入PATH环境变量中

新建个工程看配置中出现vcpkg即成功
在这里插入图片描述

有些文件可能下载失败
2022-2-21 23:58:33
这里我统一打包,放到对应 downloads目录下,可能过期
https://download.youkuaiyun.com/download/u012787710/81785983

在这里插入图片描述

vc 源文件中引用即可,不需额外配置了

#include <iostream>
#include <windows.h>

#include <detours/detours.h>
#include <json/json.h>

void main()
{
	DetourTransactionBegin();

	Json::Reader reader;
	Json::Value root;

	if (reader.parse("{\"code\":200}", root)) {
		printf("code:%d\n", root["code"].asInt());// 200
	}
	system("pause");
}

在这里插入图片描述

附录相关命令参数

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 --outdated         Uninstall all out-of-date packages
  vcpkg list                      List installed packages
  vcpkg update                    Display list of packages for updating
  vcpkg upgrade                   Rebuild all outdated packages
  vcpkg x-history <pkg>           (Experimental) Shows the history of CONTROL versions of a package
  vcpkg hash <file> [alg]         Hash a file by specific algorithm, default SHA512
  vcpkg help topics               Display the list of help topics
  vcpkg help <topic>              Display help for a specific topic

  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 integrate powershell      Enable PowerShell tab-completion

  vcpkg export <pkg>... [opt]...  Exports a package
  vcpkg edit <pkg>                Open up a port for editing (uses %EDITOR%, default 'code')
  vcpkg create <pkg> <url> [archivename]
                                  Create a new package
  vcpkg x-init-registry <path>    Initializes a registry in the directory <path>
  vcpkg format-manifest --all     Formats all vcpkg.json files. Run this before committing to vcpkg.
  vcpkg owns <pat>                Search for files in installed packages
  vcpkg depend-info <pkg>...      Display a list of dependencies for packages
  vcpkg env                       Creates a clean shell environment for development or compiling
  vcpkg version                   Display version information
  vcpkg contact                   Display contact information to send feedback

Options:
  --triplet=<t>                   Specify the target architecture triplet. See 'vcpkg help triplet'
                                  (default: %VCPKG_DEFAULT_TRIPLET%)
  --host-triplet=<t>              Specify the host architecture triplet. See 'vcpkg help triplet'
                                  (default: %VCPKG_DEFAULT_HOST_TRIPLET%)
  --overlay-ports=<path>          Specify directories to be used when searching for ports
                                  (also: %VCPKG_OVERLAY_PORTS%)
  --overlay-triplets=<path>       Specify directories containing triplets files
                                  (also: %VCPKG_OVERLAY_TRIPLETS%)
  --binarysource=<path>           Add sources for binary caching. See 'vcpkg help binarycaching'
  --x-asset-sources=<path>        Add sources for asset caching. See 'vcpkg help assetcaching'
  --downloads-root=<path>         Specify the downloads root directory
                                  (default: %VCPKG_DOWNLOADS%)
  --vcpkg-root=<path>             Specify the vcpkg root directory
                                  (default: %VCPKG_ROOT%)
  --x-buildtrees-root=<path>      (Experimental) Specify the buildtrees root directory
  --x-install-root=<path>         (Experimental) Specify the install root directory
  --x-packages-root=<path>        (Experimental) Specify the packages root directory
  --x-json                        (Experimental) Request JSON output

  @response_file                  Specify a response file to provide additional parameters

For more help (including examples) see the accompanying README.md and docs folder.
vcpkg help triplet
Available architecture triplets
VCPKG built-in triplets:
  arm-uwp
  arm64-windows
  x64-linux
  x64-osx
  x64-uwp
  x64-windows-static
  x64-windows
  x86-windows

VCPKG community triplets:
  arm-android
  arm-ios
  arm-linux
  arm-mingw-dynamic
  arm-mingw-static
  arm-neon-android
  arm-windows-static
  arm-windows
  arm64-android
  arm64-ios
  arm64-linux
  arm64-mingw-dynamic
  arm64-mingw-static
  arm64-osx-dynamic
  arm64-osx
  arm64-uwp
  arm64-windows-static-md
  arm64-windows-static
  armv6-android
  ppc64le-linux
  s390x-linux
  wasm32-emscripten
  x64-android
  x64-freebsd
  x64-ios
  x64-linux-release
  x64-mingw-dynamic
  x64-mingw-static
  x64-openbsd
  x64-osx-dynamic
  x64-osx-release
  x64-windows-release
  x64-windows-static-md
  x86-android
  x86-freebsd
  x86-ios
  x86-mingw-dynamic
  x86-mingw-static
  x86-uwp
  x86-windows-static-md
  x86-windows-static
  x86-windows-v120
对于在Windows上使用absl库和VS2019进行开发,你可以按照以下步骤操作: 1. 首先,安装Visual Studio 2019:你可以从官方网站 https://visualstudio.microsoft.com/downloads/ 下载并安装Visual Studio 2019。 2. 在安装Visual Studio 2019时,确保选择安装"C++工作负载"以及任何其他你需要的组件。 3. 接下来,你需要安装依赖管理工具vcpkg。你可以从GitHub上的vcpkg仓库中获取最新的代码:https://github.com/microsoft/vcpkg 4. 下载vcpkg的代码后,你可以按照官方文档(https://github.com/microsoft/vcpkg#quick-start-windows)中的说明进行安装。 5. 安装完成后,打开命令提示符或PowerShell,并导航到vcpkg的安装目录。然后,运行以下命令来安装absl库: ``` vcpkg install absl ``` 6. 安装完成后,你可以在你的项目中使用absl库。在Visual Studio中,创建一个新的C++项目或打开现有项目。 7. 在项目中,右键单击解决方案资源管理器中的项目名称,然后选择“属性”选项。 8. 在属性窗口中,展开“C/C++”选项,并选择“常规”子选项。在“附加包含目录”字段中,添加vcpkg的安装目录。例如,如果你将vcpkg安装在C盘的vcpkg目录中,你需要添加以下路径: ``` C:\vcpkg\installed\x64-windows\include ``` 9. 接下来,展开“链接器”选项,并选择“常规”子选项。在“附加库目录”字段中,添加vcpkg的安装目录。例如: ``` C:\vcpkg\installed\x64-windows\lib ``` 10. 最后,在“链接器”选项下选择“输入”子选项,并在“附加依赖项”字段中添加以下库: ``` absl_synchronization.lib absl_strings.lib absl_base.lib absl_debugging_internal.lib absl_flags.lib absl_flags_commandlineflag.lib absl_flags_config.lib absl_flags_internal.lib absl_flags_marshalling.lib absl_flags_parse.lib absl_flags_program_name.lib absl_log_severity.lib absl_strings_internal.lib absl_strings_str_cat.lib absl_strings_string_view.lib absl_time.lib absl_time_zone.lib ``` 11. 现在,你可以在你的源代码中使用absl库了。记得在需要使用absl的文件中包含正确的头文件,例如: ```cpp #include <absl/strings/str_cat.h> #include <absl/time/time.h> // 其他absl头文件 ``` 12. 编译并运行你的项目,确保absl库能够成功链接和使用。 希望这些步骤能帮助到你。如果你有任何进一步的问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骇客之技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值