Use Conan: An Open Source C/C++ Package Manager | by Eldad Uzman | Feb, 2022

Managing your C/C++ packages could be messy, but it can be significantly improved

Eldad Uzman
Person leaning against a wall
Photo by Dawid Zawiła on Unsplash.
+root
- mainapp.c
- CMakeLists.txt
mainapp.c
CMakeLists.txt
cmake --build ./build --config Debug --target MyProject -j 10 --
./build/MyProject -a foo -b bar
a: foo
b: bar

Option 1. Consume source code

git submodules add https://github.com/jibsen/parg.git
[submodule "parg"]path = pargurl = https://github.com/jibsen/parg.git
git submodules init
cmake --build ./build --config Debug --target MyProject -j 10 --
./build/MyProject -a foo -b bar
a: foo
b: bar

Option 2 . Consume compiled library

cmake --build ./build --config Debug --target MyProject -j 10 --
./build/MyProject -a foo -b bar
a: foo
b: bar

Option 3. Use Conan for crying out loud!

pip install conan
conan profile new myprofile
Empty profile created: C:Usersuser.conanprofilesmyprofile
[env]CC=C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exeCXX=C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe[settings]os_build=Windowsarch_build=x86os=Windowsarch=x86compiler=gcccompiler.version=8compiler.libcxx=libstdc++11build_type=Release
[requires]
parg/1.0.2
[generators]
cmake
conan install . -pr=myprofile
Configuration:
[settings]
arch=x86
arch_build=x86
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=8
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
CC=C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe
CXX=C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe
conanfile.txt: Installing package
Requirements
parg/1.0.2 from 'conancenter' - Cache
Packages
parg/1.0.2:a955db98e980a5ab86ae50d6df8bfee361185c27 - Cache
Installing (downloading, building) binaries...
parg/1.0.2: Already installed!
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generator cmake created conanbuildinfo.cmake
conanfile.txt: Aggregating env generators
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
cmake --build ./build --config Debug --target MyProject -j 10 --
./build/MyProject -a foo -b bar
a: foo
b: bar

Leave a Comment