[2026] Conan for C++ | CMakeDeps, Profiles, Lockfiles & Private Remotes
이 글의 핵심
Conan 2.x tutorial: conanfile.txt/py, CMakeDeps/CMakeToolchain, profiles, lockfiles, Docker—modern C++ package management vs vcpkg for SEO.
What is Conan? why you need it
Problem Scenario: Dependency Hell
Problem: I’m trying to use Boost, fmt, spdlog, and OpenSSL in a C++ project. You must manually download each library, build it, and hardcode the header/library paths into CMakeLists.txt. If team members’ environments are different, the path will be different, causing the build to break, and the entire process must be repeated when updating the version.
Solution: Conan is a C++ package manager, like pip in Python and npm in Node.js. If you specify dependencies in conanfile.txt, Conan automatically downloads, builds, and creates a CMake configuration file. Team members can configure the same environment by simply running conan install.
다음은 mermaid를 활용한 상세한 구현 코드입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
flowchart LR
subgraph input[input]
conanfile[conanfile.txt\nboost/1.80.0\nfmt/9.1.0]
end
subgraph conan[Conan]
install["conan install"]
download["Download package"]
build["Build (if needed)"]
gen["Generate CMake file"]
end
subgraph output[output]
cmake[conan_toolchain.cmake]
deps[CMakeDeps]
end
conanfile --> install
install --> download
download --> build
build --> gen
gen --> cmake
gen --> deps
index
- Conan installation and basic usage
- conanfile.txt vs conanfile.py
- CMake integration
- Profiles and Settings
- Frequently occurring problems and solutions
- Production Patterns
- Complete example: multi-library project
1. Conan installation and basic use
installation
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Install with pip
pip install conan
# Check version
conan --version
# Conan 2.x recommended
Basic workflow
다음은 bash를 활용한 상세한 구현 코드입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
# 1. Create conanfile.txt
cat > conanfile.txt << 'EOFC'
[requires]
boost/1.80.0
fmt/9.1.0
[generators]
CMakeDeps
CMakeToolchain
EOFC
# 2. Install dependencies
conan install . --output-folder=build --build=missing
#3. CMake build
cd build
cmake ...-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build .
conanfile.txt structure
아래 코드는 ini를 사용한 구현 예제입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
[requires]
boost/1.80.0
fmt/9.1.0
spdlog/1.11.0
[generators]
CMakeDeps
CMakeToolchain
[options]
boost:shared=False
fmt:header_only=True
2. conanfile.txt vs conanfile.py
conanfile.txt (simple project)
아래 코드는 ini를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
[requires]
boost/1.80.0
fmt/9.1.0
[generators]
CMakeDeps
CMakeToolchain
conanfile.py (complex project)
다음은 python를 활용한 상세한 구현 코드입니다. 필요한 모듈을 import하고, 클래스를 정의하여 데이터와 기능을 캡슐화하며. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
from conan import ConanFile
from conan.tools.cmake import cmake_layout
class MyProjectConan(ConanFile):
name = "myproject"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
def requirements(self):
self.requires("boost/1.80.0")
self.requires("fmt/9.1.0")
# conditional dependency
if self.settings.os == "Linux":
self.requires("openssl/3.0.0")
def configure(self):
# Option settings
self.options[boost].shared = False
def layout(self):
cmake_layout(self)
def generate(self):
# Custom creation logic
pass
3. CMake integration
CMakeLists.txt
다음은 cmake를 활용한 상세한 구현 코드입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
cmake_minimum_required(VERSION 3.20)
project(MyProject)
set(CMAKE_CXX_STANDARD 20)
# Use files generated by Conan
find_package(Boost REQUIRED COMPONENTS filesystem)
find_package(fmt REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE
Boost::filesystem
fmt::fmt
)
Build script
아래 코드는 bash를 사용한 구현 예제입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
#!/bin/bash
# Install dependencies
conan install . --output-folder=build --build=missing \
-s build_type=Release \
-s compiler.cppstd=20
# CMake build
cd build
cmake ...-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release
cmake --build . -j$(nproc)
4. Profiles and Settings
Check profile
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Default profile
conan profile show default
# Profile detection
conan profile detect
Custom Profile
아래 코드는 bash를 사용한 구현 예제입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
# Create profile
cat > ~/.conan2/profiles/gcc12 << 'EOFP'
[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.cppstd=20
build_type=Release
EOFP
# Use profile
conan install . --profile=gcc12 --output-folder=build --build=missing
Installation by build type
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Debug
conan install . -s build_type=Debug --output-folder=build/debug --build=missing
# Release
conan install . -s build_type=Release --output-folder=build/release --build=missing
5. Frequently occurring problems and solutions
Issue 1: Package not found
Symptom: ERROR: Package 'boost/1.80.0' not found in local cache.
Cause: The package is not in the local cache and cannot be found remotely.
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Solution 1: Build with --build=missing
conan install . --build=missing
# Solution 2: Add remote repository
conan remote add conancenter https://center.conan.io
# Solution 3: Search for packages
conan search boost --remote=conancenter
Issue 2: Compiler version mismatch
Symptom: ERROR: Missing prebuilt package for 'boost/1.80.0'.
Cause: No prebuilt package matching the profile’s compiler version.
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Solution 1: Build locally with --build=missing
conan install . --build=missing
# Solution 2: Edit profile
conan profile detect --force
# Solution 3: Specify a specific compiler version
conan install . -s compiler.version=11 --build=missing
Issue 3: CMake integration fails
Symptom: find_package(Boost) failed.
Cause: CMAKE_TOOLCHAIN_FILE is not specified.
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# ❌ Incorrect use
cmake ..
# ✅ Correct use
cmake ...-DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
Issue 4: Build type mismatch
Symptom: Link error when installed as Debug but built as Release.
Cause: When installing Conan, build_type and CMake build type are different.
다음은 간단한 bash 코드 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Match
conan install . -s build_type=Release --output-folder=build --build=missing
cd build
cmake ...-DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
6. production pattern
Pattern 1: Support for multiple build types
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Debug
conan install . -s build_type=Debug --output-folder=build/debug --build=missing
cmake -B build/debug -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_TOOLCHAIN_FILE=build/debug/conan_toolchain.cmake
# Release
conan install . -s build_type=Release --output-folder=build/release --build=missing
cmake -B build/release -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=build/release/conan_toolchain.cmake
Pattern 2: Lock version with lock file
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Create lock file
conan lock create conanfile.txt --lockfile-out=conan.lock
# Install with lock file (exact version)
conan install . --lockfile=conan.lock --output-folder=build --build=missing
Pattern 3: Private Package Server
아래 코드는 bash를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
# Add internal company Artifactory
conan remote add company https://artifactory.company.com/conan
# certification
conan remote login company admin -p password
# installation
conan install . --remote=company
Pattern 4: Reproducible builds with Docker
아래 코드는 dockerfile를 사용한 구현 예제입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y python3-pip cmake g++
RUN pip3 install conan
WORKDIR /app
COPY conanfile.txt .
RUN conan install . --output-folder=build --build=missing
COPY . .
RUN cd build && cmake ...-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake && make
7. Complete example: HTTP server
conanfile.txt
아래 코드는 ini를 사용한 구현 예제입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
[requires]
boost/1.80.0
fmt/9.1.0
spdlog/1.11.0
openssl/3.0.0
[generators]
CMakeDeps
CMakeToolchain
[options]
boost:shared=False
boost:without_test=True
CMakeLists.txt
다음은 cmake를 활용한 상세한 구현 코드입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
cmake_minimum_required(VERSION 3.20)
project(HttpServer VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 20)
find_package(Boost REQUIRED COMPONENTS system thread)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(OpenSSL REQUIRED)
add_executable(http_server
src/main.cpp
src/server.cpp
)
target_link_libraries(http_server PRIVATE
Boost::system
Boost::thread
fmt::fmt
spdlog::spdlog
OpenSSL::SSL
)
Build
아래 코드는 bash를 사용한 구현 예제입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
# Install dependencies
conan install . --output-folder=build --build=missing -s build_type=Release
# CMake build
cd build
cmake ...-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build . -j$(nproc)
# execution
./http_server
Conan 2.x major changes
| Item | Conan 1.x | Conan 2.x |
|---|---|---|
| profile | ~/.conan/profiles | ~/.conan2/profiles |
| command | conan install. --install-folder=build | conan install. --output-folder=build |
| Generator | cmake, cmake_find_package | CMakeDeps, CMakeToolchain |
| Recipe | ConanFile | ConanFile (API change) |
organize
| concept | Description |
|---|---|
| Conan | C++ package manager |
| conanfile.txt | Simple dependency statement |
| conanfile.py | Complex build logic |
| conan install | Install dependencies and create CMake files |
| CMakeToolchain | Create CMake toolchain file |
| CMakeDeps | Create Config file for find_package |
| Conan automates dependency management for C++ projects, eliminating environment differences between team members and ensuring build reproducibility. |
FAQ
Q1: Conan vs vcpkg?
A: Conan is flexible and easy to build a private package server based on Python. vcpkg is created by Microsoft, has good Windows integration, and is simple to use. Choose based on your team environment and preferences.
Q2: conanfile.txt vs conanfile.py?
A: conanfile.txt is suitable for simple projects, conanfile.py is for complex projects that require conditional dependencies and custom build logic.
Q3: What is —build=missing?
A: If no prebuilt package is available, build it locally. It may take a while to install for the first time, but it’s fast afterward thanks to the cache.
Q4: Why do I need a profile?
A: Specify compiler, OS, architecture, build type, etc. The same package is built differently depending on the profile, so unifying the profiles across team members can eliminate differences in environments.
Q5: Where is the Conan cache?
A: Package is cached in ~/.conan2/p/. You can clean it up with conan cache clean.
Q6: What are Conan learning resources?
A:
- Conan official documentation
- Conan Center (package search)
- “Conan C++ Package Manager Guide” One-line summary: Conan lets you manage your C++ dependencies automatically. Next, it would be a good idea to read the vcpkg guide.
Good article to read together (internal link)
Here’s another article related to this topic.
- C++ vcpkg complete guide | Microsoft C++ Package Manager
- C++ CMake Complete Guide | Cross-platform build·latest CMake 3.28+ features·presets·modules
- C++ CMake find_package complete guide | External library integration
Practical tips
These are tips that can be applied right away in practice.
Debugging tips
- If you run into a problem, check the compiler warnings first.
- Reproduce the problem with a simple test case
Performance Tips
- Don’t optimize without profiling
- Set measurable indicators first
Code review tips
- Check in advance for areas that are frequently pointed out in code reviews.
- Follow your team’s coding conventions
Practical checklist
This is what you need to check when applying this concept in practice.
Before writing code
- Is this technique the best way to solve the current problem?
- Can team members understand and maintain this code?
- Does it meet the performance requirements?
Writing code
- Have you resolved all compiler warnings?
- Have you considered edge cases?
- Is error handling appropriate?
When reviewing code
- Is the intent of the code clear?
- Are there enough test cases?
- Is it documented? Use this checklist to reduce mistakes and improve code quality.