Conan is a software package manager for C and C++ developers.
It works on all operating systems, including Windows, Linux, macOS, FreeBSD, Solaris and others, and can be targeted to any platform, including desktop, server and cross-construction for embedded and bare metal devices.
It integrates with other tools such as Docker, MinGW, WSL and with all building systems, such as CMake, MSBuild, Makefiles, Meson, SCons. It can even integrate with any proprietary building system.
Conan is completely free, open source and fully decentralized. The central ConanCenter repository contains hundreds of popular open source library packages, with many precompiled binaries.
There are several ways to install Conan. Among the possibilities you can use Portage in Gentoo or Funtoo, as follows:
On Arch Linux you can use Yay:
You can also download the .deb
, .rpm
, tarball packages directly from here and install:
Or even install via pip, according to them, more recommended:
Before you will need Pip installed, example for systems that use APT:
And just run like this:
If you have any problems with the installation, try only for your user:
pip3 install conan --user
Let’s start with a basic example, let’s create an MD5 hash application that uses one of the most popular libraries for C++: Poco. We will use CMake as a build system in this case, but keep in mind that Conan works with any build system and is not limited to using only CMake.
This will be the source file of our application:
We can do the search directly through the browser at the link: https://conan.io/center, or use conan via the command line:
The --remote=conan-center
option prompts you to search online, it can be ignored unless you have the remotes.json
file properly configured in the directory: $HOME/.conan/remotes.json
.
The output will look like this:
Suppose you used the command conan inspect poco/1.9.4
(Use the help for more information: conan --help
) to inspect this version and it is just the version you want, so just install it. To do this, create a file named: conanfile.txt
within your project (in this case, the project: mymd5) with the following information:
Make sure you have CMake installed. This will generate the file
conanbuildinfo.cmake
.
To do this, run the commands:
If you want Conan to automatically detect run:
conan profile new default --detect
, if the ABI of your compiler is not compatible you will receive a “beautiful warning” and you will need to run the command indicated just above anyway.
This command will configure the file in the path: $HOME/.conan/profiles/default
, something like this:
To do this, simply run the commands:
The output will look like this:
Now let’s create the CMakeLists.txt
file based on the file: conanbuildinfo.cmake
vim CMakeLists.txt
- Outside thebuild
directory, at the root of your project.
For Linux or macOS run this command:
There, the binary md5
was generated inside the bin/md5
directory and we can already test it
Simple, right?!
For more information consult the official Conan repository.