Conan Vcpkg

mohitmishra786/low-level-dev-skills/skills/build-systems/conan-vcpkg

作者 mohitmishra786bdc58472fa9f无许可证253 个星标收录于 2026年10月9日更新于 2026年10月9日仓库3个月前更新

C/C++ package manager skill covering Conan and vcpkg. Use when adding third-party library dependencies to C/C++ projects, managing binary compatibility, integrating with CMake, or choosing between Conan and vcpkg. Activates on queries about Conan, vcpkg, C++ dependency management, conanfile.txt, vcpkg.json, CMake package integration, or C++ package managers.

AI 生成的概览

指导使用 Conan 和 vcpkg 管理 C/C++ 依赖,包括 CMake 集成与二进制兼容性。

功能
该技能提供使用 Conan 和 vcpkg 声明第三方 C/C++ 库依赖、将其集成到 CMake 构建以及管理二进制兼容性的说明。内容涵盖 vcpkg 经典模式与清单模式、Conan 2.x 的 conanfile.txt 与 conanfile.py 工作流,以及用于交叉编译的 Conan profile。它还包含两种包管理器的选择指南和常见库名称对照表。
适用场景
在为 C/C++ 项目添加第三方库依赖、配置 vcpkg.json 或 conanfile 文件,或将 Conan、vcpkg 与 CMake 集成时使用。它也适用于在 Conan 与 vcpkg 之间做选择,或排查 Conan 包构建失败的问题。
运行要求
不附带脚本,仅为说明文档。按指南操作需要 C/C++ 工具链、CMake,以及 vcpkg 或 Conan(通过 pip 安装),并需要网络访问以获取软件包和 vcpkg 仓库。

Conan and vcpkg

Purpose

Guide agents through C/C++ dependency management with Conan and vcpkg: declaring dependencies, integrating with CMake, managing binary compatibility, and choosing the right tool for a given project.

Triggers

  • "How do I add a C++ library dependency with Conan?"
  • "How do I use vcpkg with CMake?"
  • "What's the difference between Conan and vcpkg?"
  • "How do I add zlib/openssl/fmt with a package manager?"
  • "How do I create a vcpkg.json manifest?"
  • "My Conan package build is failing — how do I debug it?"

Workflow

1. Conan vs vcpkg decision

text
Which package manager?├── Team uses MSVC on Windows primarily → vcpkg (better MSVC integration)├── Need binary packages (no source builds in CI) → Conan (binary cache)├── Need cross-compilation support → Conan (profiles) or Zig-based builds├── Need a specific version of a package → Conan (flexible versioning)├── Quick project setup, just need it to work → vcpkg (simpler)└── Open-source project, broad audience → vcpkg (GitHub-integrated)

2. vcpkg setup

bash
# Clone vcpkggit clone https://github.com/microsoft/vcpkg.git./vcpkg/bootstrap-vcpkg.sh    # Linux/macOS./vcpkg/bootstrap-vcpkg.bat   # Windows
# Install packages (classic mode)./vcpkg/vcpkg install zlib curl openssl
# Integrate with CMakecmake -S . -B build \    -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake

3. vcpkg manifest mode (recommended)

json
// vcpkg.json — place at project root{    "name": "myapp",    "version": "1.0.0",    "dependencies": [        "zlib",        "curl",        { "name": "openssl", "version>=": "3.0.0" },        { "name": "boost-filesystem", "platform": "!windows" },        {            "name": "fmt",            "features": ["core"]        }    ],    "builtin-baseline": "abc123..."}
cmake
# CMakeLists.txtcmake_minimum_required(VERSION 3.20)project(myapp)
find_package(ZLIB REQUIRED)find_package(CURL REQUIRED)find_package(fmt REQUIRED)
add_executable(myapp src/main.cpp)target_link_libraries(myapp PRIVATE ZLIB::ZLIB CURL::libcurl fmt::fmt)
bash
# Build — vcpkg automatically installs dependenciescmake -S . -B build \    -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmakecmake --build build

4. Conan setup

bash
# Install Conanpip install conan
# Set up default profile (detects compiler, OS)conan profile detect
# Check your profileconan profile show

5. Conan with CMake (Conan 2.x)

ini
# conanfile.txt[requires]zlib/1.3fmt/10.2.1openssl/3.2.0
[generators]CMakeDepsCMakeToolchain
[options]openssl/*:shared=False
bash
# Install dependenciesconan install . --output-folder=build --build=missing
# Configure and buildcmake -S . -B build \    -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \    -DCMAKE_BUILD_TYPE=Releasecmake --build build
cmake
# CMakeLists.txtfind_package(ZLIB REQUIRED)find_package(fmt REQUIRED)find_package(OpenSSL REQUIRED)
add_executable(myapp src/main.cpp)target_link_libraries(myapp PRIVATE    ZLIB::ZLIB    fmt::fmt    OpenSSL::SSL OpenSSL::Crypto)

6. Conan profiles for cross-compilation

ini
# ~/.conan2/profiles/linux-arm64[settings]os=Linuxarch=armv8compiler=gcccompiler.version=12compiler.libcxx=libstdc++11build_type=Release
[buildenv]CC=aarch64-linux-gnu-gccCXX=aarch64-linux-gnu-g++
[tool_requires]# Tools that run on build machine (x86)
bash
# Cross-compileconan install . \    --profile:build=default \    --profile:host=linux-arm64 \    --output-folder=build-arm \    --build=missing

7. conanfile.py (advanced)

python
# conanfile.pyfrom conan import ConanFilefrom conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
class MyAppConan(ConanFile):    name = "myapp"    version = "1.0"    settings = "os", "compiler", "build_type", "arch"
    def requirements(self):        self.requires("zlib/1.3")        self.requires("fmt/10.2.1")        if self.settings.os == "Linux":            self.requires("openssl/3.2.0")
    def generate(self):        tc = CMakeToolchain(self)        tc.generate()        deps = CMakeDeps(self)        deps.generate()
    def build(self):        cmake = CMake(self)        cmake.configure()        cmake.build()

8. Common dependency lookup

Libraryvcpkg nameConan name
zlibzlibzlib/1.3
OpenSSLopensslopenssl/3.2.0
libcurlcurllibcurl/8.4.0
{fmt}fmtfmt/10.2.1
spdlogspdlogspdlog/1.12.0
Boostboostboost/1.83.0
nlohmann-jsonnlohmann-jsonnlohmann_json/3.11.3
googletestgtestgtest/1.14.0
Google Benchmarkbenchmarkbenchmark/1.8.3
SQLitesqlite3sqlite3/3.44.0
protobufprotobufprotobuf/4.25.1

For vcpkg baseline pinning and Conan binary cache setup, see references/package-manager-patterns.md [blocked].

Related skills

  • Use skills/build-systems/cmake for CMake integration with both Conan and vcpkg
  • Use skills/compilers/cross-gcc for cross-compilation with Conan profiles
  • Use skills/build-systems/ninja as the backend for package-managed projects

来源与署名

来源:mohitmishra786/low-level-dev-skills位于skills/build-systems/conan-vcpkg提交bdc5847

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架