【cpp/c++ summary 工具】 vcpkg 包管理器

  • 由于之前的Hunter 包管理器在Boost的构建中速度太慢,准备尝试一下vcpkg。
    在这里插入图片描述
  • vcpkg是由microsoft开发的、适用于 Windows、Linux 和 MacOS 的 C++ 库管理器。

1. 安装 vcpkg

普通安装

C:\windows\system32>git clone https://github.com/microsoft/vcpkg.git
C:\windows\system32>cd vcpkg
C:\windows\system32>.\bootstrap-vcpkg.bat  # 下载并放置vcpkg.exe文件

Visual Studio 2022安装

在这里插入图片描述

2. 安装 Boost 库

  • 初始化 : 在命令行中执行vcpkg new --application
  • 添加依赖:修改生成的vcpkg.json(或vcpkg add port boost
{
  "dependencies": [
    "boost"
  ]
}

在这里插入图片描述

  • 安装依赖:
C:\Users\multisim\source\repos\CMakeProject2>vcpkg install

在这里插入图片描述

3. 集成 vcpkg 与你的项目

C:\Users\multisim\source\repos\CMakeProject3>vcpkg integrate install
已为此 vcpkg 根应用用户范围的集成。
CMake 项目应使用:“-DCMAKE_TOOLCHAIN_FILE=C:/Program Files/Microsoft Visual Studio/2022/Community/VC/vcpkg/scripts/buildsystems/vcpkg.cmake”

所有 MSBuild C++ 项目现在可以包含(#include)任何已安装的库。系统将自动处理链接。安装新库将使它们立即可用。
  • 如果使用 CMake,尝试在 CMakeLists.txt 文件中添加 set(CMAKE_TOOLCHAIN_FILE "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/vcpkg/scripts/buildsystems/vcpkg.cmake")但是报错,后边参考vcpkg cmake 踩坑经历将cmake文件直接引入到项目中
cmake_minimum_required (VERSION 3.8)

project ("CMakeProject2")
include("C:/Program Files/Microsoft Visual Studio/2022/Community/VC/vcpkg/scripts/buildsystems/vcpkg.cmake") # https://blog.youkuaiyun.com/a2476100824/article/details/130354025

find_package(Boost CONFIG REQUIRED regex)

add_executable (CMakeProject2 "CMakeProject2.cpp" "CMakeProject2.h")

target_link_libraries(CMakeProject2 PUBLIC Boost::regex)
  • 运行效果
    在这里插入图片描述

注:

  • 同一个依赖包可能在不同的c++包管理器中有不同的名称,比如conan中的di/1.3.0和vcpkg 中的bext-di :
C:\Users\multisim\Desktop\IPFS_PROJECT\cpp-libp2p-master>vcpkg search Injection
bext-di                  1.3.0#1          C++14 Dependency Injection Library.
bext-di[extensions]                       Build with extensions included
fruit                    3.7.1            Fruit, a dependency injection framework for C++ by Google
kangaru                  4.3.2            A dependency injection container for C++11, C++14 and later
kangaru[hashtypeid]                       Enable hash based type id
结果可能已过时。运行 `git pull` 以获取最新结果。
如果未列出你的端口,请在发出和/或考虑发出拉取请求时开立问题。  -  https://github.com/Microsoft/vcpkg/issues
头文件: #ifndef APPCONFIG_H #define APPCONFIG_H #include <string> class AppConfig { public: std::string PluginPath = "C:\\Program Files\\Autodesk\\ApplicationPlugins\\PowerChina-DamJsonToDxf.bundle\\"; std::string Version = "0.0.5"; /// <summary> /// Json输出相对路径 /// </summary> std::string JsonOutputRelativePath = "datasets\\test_json\\"; /// <summary> /// Dxf输出相对路径 /// </summary> std::string DxfOutputRelativePath = "results\\"; /// <summary> /// Dxf缩略图输出相对路径 /// </summary> std::string DxfThumbRelativePath = "results\\post_img\\"; /// <summary> /// 输出文件名后缀 /// </summary> std::string FileNameSuffix = "_aid.dxf"; /// <summary> /// App绝对路径 /// </summary> std::string AppPath; /// <summary> /// Dxf转换工具绝对路径 /// </summary> std::string DxfTransToolPath; /// <summary> /// Dxf转换工具名称 /// </summary> std::string DxfTransToolName = "ais_dam_pak.exe"; /// <summary> /// 渗流计算工具绝对路径 /// </summary> std::string PermeateToolPath; /// <summary> /// 渗流计算工具名称 /// </summary> std::string PermeateToolName = "土石坝渗流参数预测工具.exe"; /// <summary> /// 渗流计算输出相对路径 /// </summary> std::string PermeateOutputPath; /// <summary> /// 稳定性计算工具绝对路径 /// </summary> std::string StableToolPath; /// <summary> /// 稳定性计算工具名称 /// </summary> std::string StableToolName = "dam_stability_cli.exe"; /// <summary> /// 稳定性计算输出相对路径 /// </summary> std::string StableOutputPath; // AppConfig(); }; #endif // APPCONFIG_H cpp文件: #include "AppConfig.h" // 构造函数初始化属性值(如果需要隐藏或更多初始化 logic,可以在这里添加) AppConfig::AppConfig() { PluginPath = "C:\\Program Files\\Autodesk\\ApplicationPlugins\\PowerChina-DamJsonToDxf.bundle\\"; Version = "0.0.5"; JsonOutputRelativePath = "datasets\\test_json\\"; DxfOutputRelativePath = "results\\"; DxfThumbRelativePath = "results\\post_img\\"; FileNameSuffix = "_aid.dxf"; AppPath = ""; // 初始化为空串,可以后面在设置 DxfTransToolPath = ""; PermeateToolPath = ""; PermeateOutputPath = "results"; // 初始化为默认值,可以根据需要修改 StableOutputPath = ""; } 将类对象json序列化存入json文件并反序列化
07-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值