好处

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

  1. Applied user-wide integration for this vcpkg root.
  2. All MSBuild C++ projects can now #include any installed libraries.
  3. Linking will be handled automatically.
  4. Installing new libraries will make them instantly available.
  5. CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=F:/GIT/vcpkg/scripts/buildsystems/vcpkg.cmake"

vcpkg工具 vs2019 - 图1

安装

  1. git clone https://github.com/Microsoft/vcpkg.git
  2. cd vcpkg
  3. bootstrap-vcpkg.bat
  4. vcpkg integrate install
  5. //安装jsoncpp 32位库 可省略冒号后内容
  6. vcpkg install jsoncpp vcpkg install jsoncpp:x86-windows
  7. //安装jsoncpp detours位库
  8. vcpkg install detours:x64-windows //安装
  9. //如果想在任意位置使用vcpkg 请把 vcpkg.exe 路径加入PATH环境变量中

新建个工程看配置中出现vcpkg即成功
vcpkg工具 vs2019 - 图2

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

vcpkg工具 vs2019 - 图3

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

  1. #include <iostream>
  2. #include <windows.h>
  3. #include <detours/detours.h>
  4. #include <json/json.h>
  5. void main()
  6. {
  7. DetourTransactionBegin();
  8. Json::Reader reader;
  9. Json::Value root;
  10. if (reader.parse("{\"code\":200}", root)) {
  11. printf("code:%d\n", root["code"].asInt());// 200
  12. }
  13. system("pause");
  14. }

vcpkg工具 vs2019 - 图4

附录相关命令参数

  1. vcpkg --help
  2. Commands:
  3. vcpkg search [pat] Search for packages available to be built
  4. vcpkg install <pkg>... Install a package
  5. vcpkg remove <pkg>... Uninstall a package
  6. vcpkg remove --outdated Uninstall all out-of-date packages
  7. vcpkg list List installed packages
  8. vcpkg update Display list of packages for updating
  9. vcpkg upgrade Rebuild all outdated packages
  10. vcpkg x-history <pkg> (Experimental) Shows the history of CONTROL versions of a package
  11. vcpkg hash <file> [alg] Hash a file by specific algorithm, default SHA512
  12. vcpkg help topics Display the list of help topics
  13. vcpkg help <topic> Display help for a specific topic
  14. vcpkg integrate install Make installed packages available user-wide. Requires admin
  15. privileges on first use
  16. vcpkg integrate remove Remove user-wide integration
  17. vcpkg integrate project Generate a referencing nuget package for individual VS project use
  18. vcpkg integrate powershell Enable PowerShell tab-completion
  19. vcpkg export <pkg>... [opt]... Exports a package
  20. vcpkg edit <pkg> Open up a port for editing (uses %EDITOR%, default 'code')
  21. vcpkg create <pkg> <url> [archivename]
  22. Create a new package
  23. vcpkg x-init-registry <path> Initializes a registry in the directory <path>
  24. vcpkg format-manifest --all Formats all vcpkg.json files. Run this before committing to vcpkg.
  25. vcpkg owns <pat> Search for files in installed packages
  26. vcpkg depend-info <pkg>... Display a list of dependencies for packages
  27. vcpkg env Creates a clean shell environment for development or compiling
  28. vcpkg version Display version information
  29. vcpkg contact Display contact information to send feedback
  30. Options:
  31. --triplet=<t> Specify the target architecture triplet. See 'vcpkg help triplet'
  32. (default: %VCPKG_DEFAULT_TRIPLET%)
  33. --host-triplet=<t> Specify the host architecture triplet. See 'vcpkg help triplet'
  34. (default: %VCPKG_DEFAULT_HOST_TRIPLET%)
  35. --overlay-ports=<path> Specify directories to be used when searching for ports
  36. (also: %VCPKG_OVERLAY_PORTS%)
  37. --overlay-triplets=<path> Specify directories containing triplets files
  38. (also: %VCPKG_OVERLAY_TRIPLETS%)
  39. --binarysource=<path> Add sources for binary caching. See 'vcpkg help binarycaching'
  40. --x-asset-sources=<path> Add sources for asset caching. See 'vcpkg help assetcaching'
  41. --downloads-root=<path> Specify the downloads root directory
  42. (default: %VCPKG_DOWNLOADS%)
  43. --vcpkg-root=<path> Specify the vcpkg root directory
  44. (default: %VCPKG_ROOT%)
  45. --x-buildtrees-root=<path> (Experimental) Specify the buildtrees root directory
  46. --x-install-root=<path> (Experimental) Specify the install root directory
  47. --x-packages-root=<path> (Experimental) Specify the packages root directory
  48. --x-json (Experimental) Request JSON output
  49. @response_file Specify a response file to provide additional parameters
  50. 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