본문으로 건너뛰기 [2026] C++ Conan Basics — Install, conanfile, Profiles, CMake Integration [#53-4]

[2026] C++ Conan Basics — Install, conanfile, Profiles, CMake Integration [#53-4]

[2026] C++ Conan Basics — Install, conanfile, Profiles, CMake Integration [#53-4]

이 글의 핵심

Hands-on Conan 2.x basics for C++: install, conanfile, profiles, remotes, package creation, and CMake integration. Scenarios: manual deps are painful, find_package(fmt) fails, CI differs from local, teammates use different spdlog versions, Windows vs Linux, version conflicts, long READMEs for new hires.

Introduction: “I want to escape dependency hell with Conan”

Problem scenarios

"I want to use fmt, but manually downloading, building, and setting paths is too tedious."
"find_package(fmt) could not find — CMake cannot find fmt."
"It builds locally but fails only in CI."
"Teammate A uses spdlog 1.10, I use 1.12 — versions are out of sync."
"It works on Windows but not on Linux."
"Dependency A needs fmt 9.x and B needs fmt 10.x — I get a version conflict."
"New hires need to read a 10-page README just to build the project."

This article is a Conan 2.x fundamentals guide. It covers installation through conanfile, profiles, remotes, basic package creation, and CMake integration with practical examples. It also includes real-world scenarios, frequent errors, best practices, and production patterns (~900 lines).

After reading this article you will be able to:

  • Install Conan 2.x and apply it to a project
  • Declare dependencies with conanfile.txt and conanfile.py
  • Manage per-platform and per-compiler build settings with profiles
  • Add remotes and fetch packages from Conan Center or an internal registry
  • Understand the basic package-creation flow
  • Recognize common errors and how to fix them

Requirements: Python 3.8+, Conan 2.x, CMake 3.16+, C++17 recommended


Practical experience: This post is based on problems and fixes from large C++ codebases. It includes pitfalls and debugging tips that books and docs often skip.

Problem scenarios in detail

Scenario 1: Manual dependency hell

Situation: Need fmt, spdlog, nlohmann_json in the project
Problem: Each needs download·build·include/lib path wiring
Result: Everyone has different paths and versions

Scenario 2: find_package failures

Situation: CMakeLists.txt has find_package(fmt REQUIRED)
Problem: fmt was installed manually but CMake still cannot find it
Result: You must set CMAKE_PREFIX_PATH, FMT_ROOT, etc. by hand

Scenario 3: CI vs local mismatch

Situation: Build succeeds locally, fails on GitHub Actions
Problem: Libraries are not installed in CI
Result: You need conan install in the CI script

Scenario 4: Version skew

Situation: spdlog depends on fmt, nlohmann_json also depends on fmt
Problem: spdlog wants fmt 9.x, nlohmann_json wants fmt 10.x
Result: Version conflict — Conan resolves it or you need an override

Scenario 5: Platform differences

Situation: Building on Windows (MSVC), Linux (GCC), macOS (Clang)
Problem: Each compiler/architecture needs different binaries
Result: Separate settings with Conan profiles
flowchart TB
  subgraph Problems[Problems you hit in practice]
    P1[Manual path wiring]
    P2[find_package failures]
    P3[CI vs local mismatch]
    P4[Version conflicts]
    P5[Platform differences]
  end
  subgraph Solutions[Solved with Conan]
    S1[Declare in conanfile]
    S2[CMakeToolchain integration]
    S3[conan install in CI]
    S4[Override·lockfile]
    S5[Profile separation]
  end
  P1 --> S1
  P2 --> S2
  P3 --> S3
  P4 --> S4
  P5 --> S5

Table of contents

  1. Installing Conan
  2. conanfile.txt — declaring dependencies
  3. conanfile.py — advanced consumption
  4. Profiles — build environment
  5. Remotes — package sources
  6. Package creation basics
  7. CMake integration
  8. Common errors and fixes
  9. Best practices
  10. Production patterns
  11. Implementation checklist

1. Installing Conan

1.1 Requirements

ItemVersionNotes
Python3.8+Required for Conan 2.x
CMake3.16+When using CMakeToolchain
C++ compilerGCC 9+, Clang 10+, MSVC 2019+
# Create a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate   # Linux/macOS
# .venv\Scripts\activate   # Windows
# Install Conan
pip install conan
# Check version
conan --version
# Conan version 2.x.x

1.3 System Python

# Per-user install
pip install --user conan
# Or system-wide (admin)
pip install conan

1.4 Verify installation

# Conan runs
conan --version
# Default profile path
conan profile path default
# Auto-detect profile (system compiler)
conan profile detect --force

1.5 Conan 1.x vs 2.x

Important: Conan 2.x is not compatible with 1.x. Profile format, conan install options, and cache paths differ. This article targets Conan 2.x.

# Default Conan 2.x cache paths
# Linux/macOS: ~/.conan2/
# Windows: C:\Users\<user>\.conan2\

2. conanfile.txt — declaring dependencies

2.1 What is conanfile.txt?

conanfile.txt is a simple format for consuming packages. List packages under [requires] and CMake integration generators under [generators].

2.2 Full conanfile.txt example

[requires]
fmt/10.1.1
spdlog/1.12.1
nlohmann_json/3.11.2
[generators]
CMakeDeps
CMakeToolchain
[options]
spdlog:shared=False
spdlog:wchar_support=False

Section overview:

  • [requires]: required packages and versions
  • [generators]: emit CMake config so find_package can locate packages
  • [options]: per-package options (optional)

2.3 Version specifiers

[requires]
fmt/10.1.1              # exact version
spdlog/[>=1.10.0]       # minimum version
# Range (Conan 2.x)
# fmt/[>=10.0,<11]      # 10.x line

2.4 Project layout

my-conan-app/
├── conanfile.txt
├── CMakeLists.txt
├── src/
│   └── main.cpp
└── build/

2.5 Installing dependencies

What happens inside conan install:

conan install . --output-folder=build --build=missing

1. Parse conanfile:
   
   Read conanfile.txt:
   [requires]
   fmt/10.1.1
   spdlog/1.12.1
   nlohmann_json/3.11.2
   

   
   Initialize dependency graph:
   app (root)
   ├─ fmt/10.1.1
   ├─ spdlog/1.12.1
   └─ nlohmann_json/3.11.2

2. Transitive dependency resolution:
   
   Inspect spdlog/1.12.1 conanfile.py:
   def requirements(self):
       self.requires("fmt/9.1.0")
   
   Update graph:
   app
   ├─ fmt/10.1.1 (direct)
   ├─ spdlog/1.12.1
   │  └─ fmt/9.1.0 (required by spdlog)  ← version conflict!
   └─ nlohmann_json/3.11.2

3. Conflict resolution:
   
   Detected conflict:
   - app → fmt/10.1.1
   - spdlog → fmt/9.1.0
   
   Check version ranges:
   spdlog requirement: fmt/[>=9.1.0,<11]
   
   Strategy:
   a. Prefer higher version (within range):
      pick fmt/10.1.1 (compatible with 9.1.0 intent)
      → satisfies spdlog range
   
   b. If range cannot be satisfied:
      ERROR: Version conflict
      → override or lockfile needed
   
   Final graph:
   app
   ├─ fmt/10.1.1 ✓
   ├─ spdlog/1.12.1
   │  └─ fmt/10.1.1 (shared)
   └─ nlohmann_json/3.11.2

4. Package ID:
   
   Each package gets a binary ID, e.g. for fmt/10.1.1:
   Hash = hash(
       name: fmt
       version: 10.1.1
       settings:
           os: Linux
           arch: x86_64
           compiler: gcc-12
           build_type: Release
       options:
           header_only: False
   )
   
   Example ID: fmt/10.1.1:abc123def456...
   
   Used to look up binaries in cache/remote

5. Cache lookup:
   
   Search ~/.conan2/p/:
   
   fmt/10.1.1:abc123... → in cache ✓
   spdlog/1.12.1:def456... → missing ✗
   nlohmann_json/3.11.2:ghi789... → in cache ✓

6. Remote download:
   
   Missing package:
   spdlog/1.12.1:def456...
   
   Search remotes in order:
   1. mycompany → not found
   2. conancenter → found!
   
   Download:
   https://center.conan.io/.../spdlog-1.12.1-Linux-x86_64-gcc12-Release.tgz

   ~/.conan2/p/spdlog.../p/

7. --build=missing:
   
   If no binary exists, build from source:
   
   1. Fetch sources:
      git clone https://github.com/gabime/spdlog.git
   
   2. Run conanfile.py build():
      cmake -B build -S .
      cmake --build build
   
   3. Run package():
      cmake --install build --prefix=package/
   
   4. Store in cache:
      ~/.conan2/p/spdlog.../p/
      ├── include/
      ├── lib/
      └── conaninfo.txt

8. Generators:
   
   CMakeToolchain:
   emits: build/conan_toolchain.cmake
   
   Contents include:
   set(CMAKE_CXX_COMPILER /usr/bin/g++-12)
   set(CMAKE_BUILD_TYPE Release)
   list(APPEND CMAKE_PREFIX_PATH 
       ~/.conan2/p/fmt.../p
       ~/.conan2/p/spdlog.../p
       ~/.conan2/p/nlohmann_json.../p
   )
   
   CMakeDeps:
   emits: build/fmt-config.cmake
          build/spdlog-config.cmake
          build/nlohmann_json-config.cmake
   
   fmt-config.cmake example:
   add_library(fmt::fmt STATIC IMPORTED)
   set_target_properties(fmt::fmt PROPERTIES
       IMPORTED_LOCATION ~/.conan2/p/fmt.../p/lib/libfmt.a
       INTERFACE_INCLUDE_DIRECTORIES ~/.conan2/p/fmt.../p/include
   )

9. Output artifacts:
   
   build/
   ├── conan_toolchain.cmake
   ├── conanbuild.sh
   ├── conandeps.cmake
   ├── fmt-config.cmake
   ├── spdlog-config.cmake
   └── nlohmann_json-config.cmake

Typical timing:
- Cache hit: ~1s
- Remote download: ~5–10s
- Source build: ~30–300s (depends on package size)
# Emit conan_toolchain.cmake etc. under build/
conan install . --output-folder=build --build=missing
# Use a specific profile
conan install . --output-folder=build --build=missing -pr=default
# Debug build
conan install . --output-folder=build --build=missing -s build_type=Debug

—build=missing: If Conan Center has no binary for your settings, build from source.

3. conanfile.py — advanced consumption

3.1 conanfile.txt vs conanfile.py

FormatUse caseConditional depsOptions
conanfile.txtSimple declarationsNoLimited
conanfile.pyAdvanced consumption·packagingYesFull control

3.2 Consumer conanfile.py example

from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.build import check_min_cppstd
class MyAppConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeDeps", "CMakeToolchain"
    def layout(self):
        cmake_layout(self)
    def requirements(self):
        self.requires("fmt/10.1.1")
        self.requires("spdlog/1.12.1")
        self.requires("nlohmann_json/3.11.2")
    def configure(self):
        check_min_cppstd(self, "17")
    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self)
        tc.generate()

3.3 Conditional dependencies

def requirements(self):
    self.requires("fmt/10.1.1")
    self.requires("spdlog/1.12.1")
    if self.settings.os == "Linux":
        self.requires("libcurl/8.5.0")
    if self.settings.build_type == "Debug":
        self.requires("gtest/1.14.0")  # tests

3.4 Package options

def requirements(self):
    self.requires("spdlog/1.12.1")
    # spdlog options: shared, wchar_support, etc.
    # Pass with: conan install -o spdlog:shared=True
# Build shared libraries
conan install . --output-folder=build -o spdlog:shared=True

4. Profiles — build environment

4.1 What is a profile?

A profile defines OS, architecture, compiler, build type, and related settings. Conan picks or builds binaries to match the profile.

4.2 Inspect the default profile

conan profile show default
conan profile path default

4.3 Auto-detect

conan profile detect --force
conan profile show default

4.4 Example profile file

# conan/profiles/linux-gcc12
[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
build_type=Release
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

4.5 Windows profile

# conan/profiles/windows-msvc2022
[settings]
os=Windows
arch=x86_64
compiler=msvc
compiler.version=193
compiler.runtime=dynamic
build_type=Release
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

4.6 macOS profile

# conan/profiles/macos-clang
[settings]
os=Macos
arch=armv8
compiler=apple-clang
compiler.version=15
compiler.libcxx=libc++
build_type=Release

4.7 Using profiles

conan install . --output-folder=build -pr=conan/profiles/linux-gcc12
conan install . --output-folder=build -pr=default -o spdlog:shared=True

4.8 Profile layout

my-project/
├── conanfile.txt
├── conan/
│   └── profiles/
│       ├── default
│       ├── linux-gcc12
│       ├── windows-msvc2022
│       └── macos-clang
└── CMakeLists.txt

5. Remotes — package sources

5.1 What is a remote?

A remote is where Conan downloads packages. Conan Center is registered by default.

5.2 List remotes

conan remote list
# Example:
# conancenter: https://center.conan.io [VerifySSL: True]

5.3 Add a remote (internal Artifactory)

conan remote add mycompany https://mycompany.jfrog.io/artifactory/api/conan/conan-local
conan remote list

5.4 Remote order

# Remotes are searched in list order
conan remote list
# Prefer internal: insert at position 0
conan remote add mycompany https://.... --insert=0
conan remote remove mycompany

5.5 Search packages

conan search fmt --remote=conancenter
conan search fmt --remote=conancenter -q="*"
conan search lib-core --remote=mycompany

5.6 Remote flow

sequenceDiagram
  participant Dev as Developer
  participant Conan as Conan
  participant CC as Conan Center
  participant Corp as Internal remote
  Dev->>Conan: conan install
  Conan->>Conan: search remotes in order
  Conan->>Corp: 1. internal remote
  alt package found
    Corp-->>Conan: package
  else not found
    Conan->>CC: 2. Conan Center
    CC-->>Conan: package
  end
  Conan->>Dev: build/conan_toolchain.cmake

6. Package creation basics

6.1 Packaging flow

Conan packages are defined by a recipe (conanfile.py). conan create builds, packages, and stores in the cache. For recipe details see Writing Conan recipes.

6.2 Minimal conanfile.py (library package)

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
class MylibConan(ConanFile):
    name = "mylib"
    version = "1.0.0"
    settings = "os", "compiler", "build_type", "arch"
    exports_sources = "CMakeLists.txt", "src/*", "include/*"
    def layout(self):
        cmake_layout(self)
    def generate(self):
        tc = CMakeToolchain(self)
        tc.generate()
    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()
    def package(self):
        cmake = CMake(self)
        cmake.install()
    def package_info(self):
        self.cpp_info.libs = ["mylib"]

6.3 Run conan create

conan create .
conan create . -s build_type=Debug
conan create . -pr=default

6.4 Consuming your package

# After conan create, mylib/1.0.0 is in the cache
# Reference it from conanfile.txt:
[requires]
mylib/1.0.0
fmt/10.1.1
[generators]
CMakeDeps
CMakeToolchain

7. CMake integration

7.1 End-to-end flow

1. conan install → build/conan_toolchain.cmake, build/fmt-config.cmake, ...
2. cmake -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake ...
3. find_package(fmt) uses Conan-generated config files

7.2 CMakeLists.txt example

cmake_minimum_required(VERSION 3.20)
project(my-conan-app VERSION 1.0.0 LANGUAGES CXX)
# Conan toolchain must load first (via CMAKE_TOOLCHAIN_FILE on configure)
add_executable(my-app src/main.cpp)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(nlohmann_json REQUIRED)
target_link_libraries(my-app PRIVATE
    fmt::fmt
    spdlog::spdlog
    nlohmann_json::nlohmann_json
)
target_compile_features(my-app PRIVATE cxx_std_17)

7.3 Build script

#!/bin/bash
# build.sh
set -e
BUILD_DIR=build
echo "=== Conan install ==="
conan install . --output-folder=$BUILD_DIR --build=missing
echo "=== CMake configure ==="
cmake -B $BUILD_DIR -S . -DCMAKE_TOOLCHAIN_FILE=$BUILD_DIR/conan_toolchain.cmake
echo "=== CMake build ==="
cmake --build $BUILD_DIR
echo "=== Run ==="
./$BUILD_DIR/my-app

7.4 main.cpp example

#include <spdlog/spdlog.h>
#include <fmt/core.h>
#include <nlohmann/json.hpp>
int main() {
    spdlog::info("Conan basics example");
    spdlog::info("fmt: {}", fmt::format("Hello, {}!", "Conan"));
    nlohmann::json j = {{"app", "my-conan-app"}, {"version", "1.0.0"}};
    spdlog::info("JSON: {}", j.dump());
    return 0;
}

7.5 CMake integration diagram

flowchart LR
  subgraph Conan[Conan]
    C1[conan install] --> C2[conan_toolchain.cmake]
    C2 --> C3[fmt-config.cmake]
    C2 --> C4[spdlog-config.cmake]
  end
  subgraph CMake[CMake]
    M1[CMAKE_TOOLCHAIN_FILE] --> M2[find_package]
    M2 --> M3[target_link_libraries]
  end
  C2 --> M1
  C3 --> M2
  C4 --> M2

7.6 Minimal runnable project

Layout:

my-conan-app/
├── conanfile.txt
├── CMakeLists.txt
├── build.sh
└── src/
    └── main.cpp

conanfile.txt:

# Runnable example
[requires]
fmt/10.1.1
spdlog/1.12.1
[generators]
CMakeDeps
CMakeToolchain

CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
project(my-conan-app LANGUAGES CXX)
add_executable(my-app src/main.cpp)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
target_link_libraries(my-app PRIVATE fmt::fmt spdlog::spdlog)
target_compile_features(my-app PRIVATE cxx_std_17)

src/main.cpp:

#include <spdlog/spdlog.h>
#include <fmt/core.h>
int main() {
    spdlog::info("{}", fmt::format("Hello, Conan!"));
    return 0;
}

Build:

conan install . --output-folder=build --build=missing
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
cmake --build build
./build/my-app

8. Common errors and fixes

Error 1: “Could NOT find a package configuration file provided by ‘fmt’”

Symptom:

CMake Error at ...: Could not find a package configuration file provided by "fmt"

Cause: conan install was not run, or CMAKE_TOOLCHAIN_FILE is not set to Conan’s conan_toolchain.cmake. Fix:

conan install . --output-folder=build --build=missing
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=$(pwd)/build/conan_toolchain.cmake

Error 2: “Version conflict”

Symptom:

ERROR: Version conflict: spdlog/1.12.1 requires fmt/9.1.0, nlohmann_json/3.11.2 requires fmt/10.1.1

Fix 1 — conanfile.txt:

# Pin fmt at the top level
[requires]
fmt/10.1.1
spdlog/1.12.1
nlohmann_json/3.11.2

Declaring fmt/10.1.1 explicitly lets Conan converge on that version. Fix 2 — conanfile.py override:

def requirements(self):
    self.requires("spdlog/1.12.1")
    self.requires("nlohmann_json/3.11.2")
    self.requires("fmt/10.1.1", override=True)

Error 3: “conan_toolchain.cmake not found”

Cause: conan install was not run, or --output-folder does not match CMake -B. Fix:

conan install . --output-folder=build --build=missing
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake

Error 4: “Package ‘fmt/10.1.1’ not found”

Cause: That version is not on Conan Center, or remote configuration is wrong. Fix:

conan search fmt --remote=conancenter
conan search fmt --remote=conancenter -q="*"
conan remote list

Error 5: “Build type mismatch”

Symptom: You configured Debug but linked Release libraries — ABI issues. Fix:

conan profile show default
conan install . --output-folder=build --build=missing -s build_type=Debug

Error 6: “Invalid configuration: compiler.version ‘12’ is not valid”

Cause: Installed GCC version does not match the profile. Fix:

gcc --version
conan profile detect --force

Error 7: “Binary missing” / “Can’t find a compatible binary”

Symptom:

WARN: fmt/10.1.1: Binary missing

Cause: No prebuilt binary for your OS/compiler/arch on Conan Center. Fix:

conan install . --output-folder=build --build=missing
conan install . --output-folder=build --build=fmt --build=spdlog

Error 8: “Python not found” / “Conan requires Python 3.8+”

Cause: Python before 3.8 or PATH issues. Fix:

python3 --version
python3 -m pip install conan

Error 9: “ERROR: Lockfile ‘conan.lock’ is outdated”

Cause: conanfile.txt changed but the lockfile was not refreshed. Fix:

conan lock create . --lockfile-out=conan.lock

Error 10: On Windows, “MSVC not found”

Cause: Visual Studio not installed, or not in a Developer Command Prompt. Fix:

# Run from Visual Studio Developer Command Prompt
# or run vcvarsall.bat first
conan profile detect --force

9. Best practices

9.1 Pin versions

# Prefer exact versions
fmt/10.1.1
# Ranges lower reproducibility
# fmt/[>=10.0]

9.2 Order of operations

conan install . --output-folder=build --build=missing
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
cmake --build build

9.3 Share profiles

Commit conan/profiles/ so everyone uses the same profiles

9.4 Lockfiles for reproducible builds

conan lock create .
conan install . --output-folder=build --lockfile=conan.lock --build=missing

9.5 .gitignore

# Conan / build
build/
.conan/

9.6 Best-practice summary

TopicRecommendation
VersionsExplicit versions like fmt/10.1.1
LockfileCommit conan.lock
ProfilesShared team profiles
CIAlways run conan install
output-folderMatch CMake -B

10. Production patterns

10.1 Build script

#!/bin/bash
# build.sh
set -e
BUILD_DIR=build
PROFILE=${1:-default}
echo "=== Conan install (profile: $PROFILE) ==="
conan install . --output-folder=$BUILD_DIR --lockfile=conan.lock --build=missing -pr=$PROFILE
echo "=== CMake configure ==="
cmake -B $BUILD_DIR -S . -DCMAKE_TOOLCHAIN_FILE=$BUILD_DIR/conan_toolchain.cmake
echo "=== CMake build ==="
cmake --build $BUILD_DIR
echo "=== Run ==="
./$BUILD_DIR/my-app

10.2 GitHub Actions

name: Build
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Install Conan
        run: pip install conan
      - name: Cache Conan
        uses: actions/cache@v4
        with:
          path: ~/.conan2
          key: conan-${{ runner.os }}-${{ hashFiles('conanfile.*', 'conan.lock') }}
      - name: Conan install
        run: |
          conan profile detect --force
          conan install . --output-folder=build --lockfile=conan.lock --build=missing
      - name: CMake configure
        run: cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
      - name: CMake build
        run: cmake --build build

10.3 Production layout

my-conan-prod/
├── conanfile.txt
├── conan.lock
├── CMakeLists.txt
├── build.sh
├── conan/
│   └── profiles/
│       ├── default
│       ├── linux-gcc12
│       └── windows-msvc2022
└── src/
    └── main.cpp

10.4 Dependency update workflow

conan lock create . --lockfile-out=conan.lock
conan install . --output-folder=build --lockfile=conan.lock --build=missing
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
cmake --build build
git add conan.lock && git commit -m "chore: update dependencies"

11. Implementation checklist

Conan basics checklist

  • Install Conan 2.x (pip install conan)
  • Run conan profile detect --force
  • Author conanfile.txt or conanfile.py
  • After conan install, pass CMAKE_TOOLCHAIN_FILE
  • Add find_package in CMakeLists.txt
  • Link Conan targets in target_link_libraries

Production checklist

  • Create conan.lock and commit it
  • Share team profiles (conan/profiles/)
  • Run conan install in CI
  • Cache ~/.conan2 in CI
  • Provide a build.sh (or equivalent)

Error-response checklist

  • find_package fails → verify toolchain file
  • Version conflict → override or pin in conanfile
  • Binary missing → --build=missing
  • Build type mismatch → check -s build_type

Summary

TopicDescription
Installpip install conan, Conan 2.x
conanfile.txt[requires], [generators]
conanfile.pyConditional deps, options, advanced consumption
ProfilesOS, compiler, build_type, etc.
RemotesConan Center, internal Artifactory
CMakeCMAKE_TOOLCHAIN_FILE integration

Principles:

  1. Run conan install before CMake configure
  2. Point CMAKE_TOOLCHAIN_FILE at Conan’s generated file
  3. Use conan.lock for reproducible builds
  4. Share profiles so environments match

FAQ

Q. Should I use conanfile.txt or conanfile.py?

A. For simple dependency lists, conanfile.txt is enough. Use conanfile.py for conditional dependencies, options, and advanced setup.

Q. Can I use vcpkg and Conan together?

A. Using both in one project is not recommended — you risk conflicts and confusing paths. Pick one per team convention.

Q. How do I migrate from Conan 1.x to 2.x?

A. Conan 2.x is not compatible with 1.x. conanfile.txt is similar, but conan install flags and profiles differ. See the Conan 2.0 migration guide.

Q. When should I use a lockfile?

A. When you want pinned, reproducible dependencies: run conan lock create ., commit conan.lock, and in CI use --lockfile=conan.lock.

Q. How do I manage the Conan cache in production?

A. In CI, cache ~/.conan2 and key the cache by hashes of conanfile.* and conan.lock. With Artifactory you can also host binary packages internally.

References

One-line takeaway: With Conan 2.x, conanfiles, profiles, and CMake integration, you can tame dependency chaos and build reproducibly.

Next: [C++ #53-4] Writing Conan recipes — packages, build, remotes

Previous: [C++ #53-3] Creating vcpkg ports — build and publish


  • C++ Conan advanced — lockfiles, cross-build, internal registry
  • C++ Writing Conan recipes
  • C++ vcpkg basics
  • C++ Conan overview
  • CMake intro