Conan C/C++ Package Manager
Conan is an open-source C/C++ package manager that facilitates dependency management and binary distribution for C and C++ projects. It offers significant flexibility for integrating with various build systems, compilers, and configurations across different platforms. The current version is 2.27.0, and it maintains an active development cycle with frequent releases, typically on a monthly or bi-monthly cadence.
Warnings
- breaking Conan 2.0 introduced major breaking changes compared to Conan 1.x. The Python API, recipe format (`conanfile.py`), command-line interface, and binary package formats are incompatible. Recipes and existing builds from Conan 1.x projects *must* be migrated.
- gotcha The Conan Python API (`conan.api.conan_api.ConanAPI`) is currently experimental and explicitly stated to be subject to breaking changes across minor versions. Relying heavily on it for critical automation may require frequent updates.
- gotcha Older Conan 2.x versions (specifically 2.25.0 to 2.25.2, and some 2.26.x before 2.26.2) had issues with atomic file operations during package binary downloads on Windows, often clashing with antivirus software, leading to failures or corrupted caches.
- gotcha The behavior of `conan profile detect` changed significantly from Conan 1.x to 2.x. Relying on its output as a stable baseline, especially for build automation, can lead to unexpected results in Conan 2.x.
Install
-
pip install conan
Imports
- ConanAPI
from conan.api.conan_api import ConanAPI
Quickstart
from conan.api.conan_api import ConanAPI
# Initialize the Conan API. For advanced use, cache_folder can be specified.
conan_api = ConanAPI()
print("Conan API initialized.")
# Example: List installed recipes in the local cache
# The 'list' sub-API provides methods for inspecting packages and recipes.
local_recipes = conan_api.list.recipes(query="*")
if local_recipes:
print(f"Found {len(local_recipes)} local recipes:")
for ref in local_recipes:
print(f" - {ref}")
else:
print("No recipes found in the local Conan cache.")
# Example: Get Conan's current home folder
conan_home = conan_api.home_folder
print(f"Conan home folder: {conan_home}")