DEV Community


Posted on • Updated on

How to install imgui-sfml from conan

Conan is a powerful C++ package manager which simplify a lot the dependency managment in your projects.

Here I will talk about the installation of imgui-sfml from the perspective of someone who has never used it.


To follow this tutorial you will need to have on your machine :

  • Python3 (we will use pip to install conan)
  • CMake

Conan Installation

First we will need to install conan.
In your project directory run

$ python -m venv venv
$ source venv/bin/activate
$ pip install conan
$ conan
$ conan remote add bincrafters
Enter fullscreen mode Exit fullscreen mode

Here is the expected output :
Output of the command  raw `conan` endraw

To deactivate the virtualenv just run

$ deactivate

Let's build the project

In this section we will use CMake but if you want to use any other generator the documentation is here.

As there is no package for imgui-sfml in conan-center we will need to download it from bincrafters.

For that we need to create a conanfile.txt at the root of the project.


Enter fullscreen mode Exit fullscreen mode

Next add those two line in your CMakeLists.txt.

cmake_minimum_required(VERSION 3.16)

Enter fullscreen mode Exit fullscreen mode

Then create the build folder and install the dependencies.

$ mkdir build
$ conan install . --install-folder ./build # You will have some error but that's normal
Enter fullscreen mode Exit fullscreen mode

The point of the last command was to generate the file ~/.conan/profile/default.

Change the libcxx version

SFML which is a dependancy of imgui-sfml needs the libstdc++11 to work properly. However conan still use libstdc++ by default for backwards compatibility so you have to edit it by yourself.

Run the command:

conan profile update settings.compiler.libcxx=libstdc++11 default
Enter fullscreen mode Exit fullscreen mode


Open the file ~/.conan/profile/default and apply the following change

Enter fullscreen mode Exit fullscreen mode

Go back to the project

Here is a code sample (from here) to test imgui-sfml.

#include "imgui.h"
#include "imgui-SFML.h"

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

int main()
    sf::RenderWindow window(sf::VideoMode(640, 480), "");

    sf::Color bgColor;

    float color[3] = { 0.f, 0.f, 0.f };

    // let's use char array as buffer, see next part
    // for instructions on using std::string with ImGui
    char windowTitle[255] = "ImGui + SFML = <3";

    window.resetGLStates(); // call it if you only draw ImGui. Otherwise not needed.
    sf::Clock deltaClock;
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {

            if (event.type == sf::Event::Closed) {

        ImGui::SFML::Update(window, deltaClock.restart());

        ImGui::Begin("Sample window"); // begin window

                                       // Background color edit
        if (ImGui::ColorEdit3("Background color", color)) {
            // this code gets called if color value changes, so
            // the background color is upgraded automatically!
            bgColor.r = static_cast<sf::Uint8>(color[0] * 255.f);
            bgColor.g = static_cast<sf::Uint8>(color[1] * 255.f);
            bgColor.b = static_cast<sf::Uint8>(color[2] * 255.f);

        // Window title text edit
        ImGui::InputText("Window title", windowTitle, 255);

        if (ImGui::Button("Update window title")) {
            // this code gets if user clicks on the button
            // yes, you could have written if(ImGui::InputText(...))
            // but I do this to show how buttons work :)
        ImGui::End(); // end window

        window.clear(bgColor); // fill background with color

Enter fullscreen mode Exit fullscreen mode

Then in your project

$ conan install . --install-folder ./build # Now you should not have any error
$ cmake . -Bbuild
$ cmake --build build
$ ./build/bin/app
Enter fullscreen mode Exit fullscreen mode

Once that's finished enjoy your application 😉.

Top comments (0)