Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] ImGui + SFML - Linker Errors (I need some advice)  (Read 3073 times)

0 Members and 1 Guest are viewing this topic.

aveholow

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
[SOLVED] ImGui + SFML - Linker Errors (I need some advice)
« on: January 15, 2021, 07:57:46 pm »
Hi.
I am trying to integrate SFML and ImGui according to this https://eliasdaler.github.io/using-imgui-with-sfml-pt1/(basic tutorial form "Elias Daler's Blog").
//  SFML working fine (I'm using DLL, not static)  //

I have followed all the steps but I am getting linker errors.
https://imgur.com/G3nB8Wi

My code is the same as on the website.

#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), "");
    window.setVerticalSyncEnabled(true);
    ImGui::SFML::Init(window);

    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.setTitle(windowTitle);
    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)) {
            ImGui::SFML::ProcessEvent(event);

            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }

        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 :)
            window.setTitle(windowTitle);
        }
        ImGui::End(); // end window

        window.clear(bgColor); // fill background with color
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();
}

This is a common problem. I read some forum topics and the solution is to link opengl32.lib to the project, and I did it , but I still get errors.
I have the assumption that I am wrong linking opengl32.lib.
I found opengl32 lib in one of my Windows Kits which I use in my project.
(C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x86\OpenGL32.Lib)
As the name suggests, I plugged OpenGL32.Lib to additional dependencies.
(my additional dependencies https://imgur.com/5Zq33Q6)

Unfortunately for me it didn't work. Anyone have an idea what I should do?
« Last Edit: January 16, 2021, 06:01:48 pm by aveholow »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: ImGui + SFML - Linker Errors (I need some advice)
« Reply #1 on: January 15, 2021, 10:53:29 pm »
i don't know if it's the solution, but from the site you linked there's a comment:

Quote from: Remisto
Just came here to say that you should also add imgui-widgets.cpp to your file. Otherwise you will stuck with LNK2019 errors.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

aveholow

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: ImGui + SFML - Linker Errors (I need some advice)
« Reply #2 on: January 16, 2021, 06:01:16 pm »
It turned out that I had to add imgui_tables.cpp. (I already had imgui_widgets.cpp added).
The guide on this page is outdated and you need to add these files now:

imgui.cpp
imgui_demo.cpp
imgui_draw.cpp
imgui_tables.cpp
imgui_widgets.cpp
imgui-SFML.cpp


and, of course link OpenGL32.lib if you have LNK errors

Stauricus thanks, your answer led me to the solution

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: [SOLVED] ImGui + SFML - Linker Errors (I need some advice)
« Reply #3 on: January 16, 2021, 11:38:33 pm »
glad I could help somehow  ;D
Visit my game site (and hopefully help funding it? )
Website | IndieDB