Skip to content

Setting up Conan

Mathis Lamidey edited this page Jan 6, 2021 · 6 revisions

Conan

Conan is an open source C++ packet manager, similar to node's npm or rust's crates.

TL;DR

If you're only here for the set-up commands, you'll find them here. However, it's always a good idea to understand these commands, so I encourage you to actually check out the rest of this page. Before proceeding, note that the following commands should only have to be run once per Conan install.

This assumes Conan is installed and in your path.

MSVC:

conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
conan remote add Morrigu-Deps https://api.bintray.com/conan/ithyx/imgui

GCC/Clang

conan profile new default --detect
conan profile update settings.compiler.libcxx=libstdc++11 default
conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
conan remote add Morrigu-Deps https://api.bintray.com/conan/ithyx/imgui

Step by step

Creating and configuring a profile

This step is optional with MSVC, but if you plan on using Conan for something else than this repo, you will probably need one anyways. To create a new Conan profile, simply run:

conan profile new default --detect

This should set a few variables automatically, like what compiler you are using, and what version it is. Conan profiles are extremely simple and portable, so you can edit one anytime with any text editor. The folder where they are stored should be at ~/.conan/profiles. At the moment, only one parameter in this file is interesting. If you are using Clang or GCC, you will find a variable named compiler.libcxx. This variable tells Conan which C++ ABI to link against. It turns out that GCC changed ABI for C++11, and you should tell Conan that you want to link against the new one. To do this, simply execute:

conan profile update settings.compiler.libcxx=libstdc++11 default

Adding remotes

Conan comes with one remote out of the box, which is the official Conan-center remote. A remote is very similar to a git repository, where binaries and recipes are stored. Without going in too much details, recipes can help you recreate binaries if they don't correspond exactly to your environment (OS, compiler, compiler version, etc...). However, a lot of libraries are getting uploaded on another popular remote: the Bincrafter's remote. To add this remote and to tell Conan to look in this remote for missing dependencies, you can run:

conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan

This will cover almost all dependencies of this project. However, while ImGui itself has a bincrafters recipe, its docking branch doesn't. That meant I had to create my own recipe and upload it to a personal remote, hence the need to add it alongside:

conan remote add Morrigu-Deps https://api.bintray.com/conan/ithyx/imgui

I can't promise I won't add anything else on this remote, but it's very unlikely. If you want to make sure this remote is queried last for recipes, you can update the remote order at anytime like this:

conan remote update Morrigu-Deps https://api.bintray.com/conan/ithyx/imgui --insert 999

Why Conan

Conan fixes a lot of problems C++ has with libraries. It is not a perfect solution at all, far from it, but I consider that the convenience it offers once it is set up is worth taking a bit of time to understand how it works. I am aware of some alternatives, namely vcpkg, and Hunter, but found Conan to be the better compromise between version granularity and package variety.

Clone this wiki locally