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

Author Topic: Im having trouble compiling SFML & ImGui  (Read 1553 times)

0 Members and 1 Guest are viewing this topic.

cassado10

  • Newbie
  • *
  • Posts: 1
    • View Profile
Im having trouble compiling SFML & ImGui
« on: August 07, 2023, 05:45:40 pm »
 I'm following the tutorial here:https://terminalroot.com/how-to-create-graphical-interfaces-with-dear-imgui-and-sfml/

    My Code looks like this:

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

#include<SFML/Graphics.hpp>

int main(){
    //Window Initialize
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
   
    //Initialize ImGui
    ImGui::SFML::Init(window);

    //shape in SFML
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Cyan);


    sf::Clock deltaClock;
    while (window.isOpen())
    {
        //Event Handling
        sf::Event event;
        while (window.pollEvent(event))
        {
            ImGui::SFML::ProcessEvent(window, event);

            if (event.type == sf::Event::Closed)
                window.close();
        }
        ImGui::SFML::Update(window, deltaClock.restart());

        ImGui::Begin("Hello World!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();
}

    2. And to compile i used the following commands using Mingw:

//the compiling part went ok

g++ -c main.cpp -IC:/SFML-2.5.1/include

//the linking part didn&#39;t work

g++ main.o -o app -LC:/SFML-2.5.1/lib -lsfml-graphics -lsfml-window -lsfml-system

    3. I get this following error:

main.o:main.cpp:(.text+0x137): undefined reference to `ImGui::SFML::Init(sf::RenderWindow&, bool)&#39;
main.o:main.cpp:(.text+0x1c5): undefined reference to `ImGui::SFML::ProcessEvent(sf::Window const&, sf::Event const&)&#39;
main.o:main.cpp:(.text+0x203): undefined reference to `ImGui::SFML::Update(sf::RenderWindow&, sf::Time)&#39;
main.o:main.cpp:(.text+0x21a): undefined reference to `ImGui::Begin(char const*, bool*, int)&#39;
main.o:main.cpp:(.text+0x247): undefined reference to `ImGui::Button(char const*, ImVec2 const&)&#39;
main.o:main.cpp:(.text+0x24c): undefined reference to `ImGui::End()&#39;
main.o:main.cpp:(.text+0x2ca): undefined reference to `ImGui::SFML::Render(sf::RenderWindow&)&#39;
main.o:main.cpp:(.text+0x2e7): undefined reference to `ImGui::SFML::Shutdown()&#39;
collect2.exe: error: ld returned 1 exit status

Any help is appreciated.

I'm not sure if these details are useful but:

    I'm using VSCode with Mingw (my laptop goes reeeeally slow if i use Visual Studio 19)

    SFML-2.5.1

    Imgui 1.88 from https://github.com/ocornut/imgui (as shown on the link)

    Imgui-sfml from https://github.com/eliasdaler/imgui-sfml (as shown on the link)

    If i'm missing anything please let me know.

Some of my secondary questions are:

    Do i need to link any .a or .dll files just like i have to do in sfml?

    I've seen other sites mention something about linking opengl. How do i do that?

    Is there another way to create a project without having to copy the files into my project file? Something like doing that whole process in C:/ and later add the default include path to VSCode preferences?
« Last Edit: August 08, 2023, 09:24:40 am by eXpl0it3r »

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Im having trouble compiling SFML & ImGui
« Reply #1 on: August 08, 2023, 01:16:47 am »
You compiled main.cpp, but you also need to compile imgui.cpp, imgui_widgets.cpp, imgui_draw.cpp, imgui_tables.cpp and imgui-sfml.cpp then link all of the produced .o files with main.o.

Thrasher

  • SFML Team
  • Jr. Member
  • *****
  • Posts: 57
    • View Profile
Re: Im having trouble compiling SFML & ImGui
« Reply #2 on: August 08, 2023, 04:52:13 pm »
https://github.com/SFML/cmake-sfml-project/blob/imgui-sfml/CMakeLists.txt

There's a much better solution in the official SFML project template repo. See the `imgui-sfml` branch above.

 

anything