Scripts2026年4月17日·1 分钟阅读

Conan — Open-Source C/C++ Package Manager

A decentralized package manager for C and C++ that handles dependency resolution, binary management, and cross-platform builds.

Introduction

Conan solves the long-standing dependency management problem for C and C++. Unlike languages with built-in package ecosystems, C/C++ projects historically relied on manual library management or system packages. Conan provides a decentralized, cross-platform solution that integrates with CMake, MSBuild, Meson, and other build systems to fetch, build, and cache binary packages for any platform and compiler combination.

What Conan Does

  • Resolves and installs C/C++ library dependencies from ConanCenter or private servers
  • Manages pre-built binaries for specific OS, compiler, and architecture combinations
  • Generates build system integration files for CMake, Meson, MSBuild, and others
  • Supports creating and publishing your own packages to private or public repositories
  • Handles transitive dependencies and version conflict resolution

Architecture Overview

Conan uses a client-server model. The Conan client reads a conanfile.py or conanfile.txt that declares dependencies, then resolves versions from one or more remote servers. For each dependency, Conan checks if a compatible binary exists in the local cache or remote. If not, it builds from source using the recipe. Packages are identified by name, version, user, channel, and a settings hash (OS, compiler, build type) to store multiple binary variants.

Self-Hosting & Configuration

  • Install via pip: pip install conan
  • Run conan profile detect to auto-configure your compiler and platform settings
  • Declare dependencies in conanfile.txt or conanfile.py at the project root
  • Host a private Conan server with Artifactory or the open-source conan_server
  • Configure remotes with conan remote add myremote https://my.server/artifactory/api/conan/repo

Key Features

  • Binary management stores pre-compiled packages for every OS/compiler/arch combination
  • ConanCenter hosts thousands of open-source C/C++ libraries with CI-verified recipes
  • Lockfiles pin exact dependency versions and revisions for reproducible builds
  • Python-based recipes (conanfile.py) allow full scripting of build and package logic
  • Cross-compilation profiles let you target embedded, mobile, and other architectures

Comparison with Similar Tools

  • vcpkg — Microsoft-backed, ports-based; Conan offers decentralized servers and binary caching
  • CMake FetchContent — downloads source at configure time; Conan provides binary caching and version management
  • Meson WrapDB — Meson-specific; Conan works with any build system
  • Spack — HPC-focused package manager; Conan targets general C/C++ development
  • Hunter — CMake-driven; Conan has a larger package index and supports non-CMake builds

FAQ

Q: Does Conan work with CMake? A: Yes. Conan generates CMake toolchain and preset files so find_package() works seamlessly.

Q: Can I host a private Conan repository? A: Yes. JFrog Artifactory has native Conan support, or you can run the lightweight open-source conan_server.

Q: What is ConanCenter? A: The central public repository of open-source C/C++ packages maintained by the community with CI-verified recipes.

Q: Does Conan support cross-compilation? A: Yes. Define a host profile and a build profile to cross-compile for targets like ARM, WebAssembly, or embedded platforms.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产