1

Since I started learning SFML, I found a lot hard to include libraries in CPP.

The two easiest ways I found was configuring Visual Studio like the tutorial, or configuring CMake with CLion.

But I don't like Visual Studio, CLion is really heavy on the machine and I just can't undestand CMake.

So I started working with VSCode and making .bat files and mingw32 g++ to build and run:

g++ ../main.cpp -o ../build/main.exe -I ${SFML_DIR}\include -L ${SFML_DIR}\lib -lsfml-graphics -lsfml-window -lsfml-system

This is the simplest for build I made, considering that the .bat file is inside and scrips folder and I want the build to be in root/build and to be named main.exe. Then I can run it using another .bat file:

"../build/main.exe"

But, for compiling it together with ImGui I'm having some problems, I try to run:

g++ ../main.cpp -o ../build/main.exe -I ${IMGUI-DIR} -L ${IMGUI-DIR} -I ${IMGUI-DIR}\backends -L ${IMGUI-DIR}\backends -I ${IMGUI-SFML-DIR} -L ${IMGUI-SFML-DIR} -I ${SFML-DIR}\include -L ${SFML-DIR}\lib -lsfml-graphics -lsfml-window -lsfml-system -lopengl32

But I always get this error:

AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x12d): undefined reference to ImGui::SFML::Init(sf::RenderWindow&, bool)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x26c): undefined reference to ImGui::SFML::ProcessEvent(sf::Event const&)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x2ac): undefined reference to ImGui::SFML::Update(sf::RenderWindow&, sf::Time)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x2c8): undefined reference to ImGui::Begin(char const*, bool*, int)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x2e6): undefined reference to ImGui::ColorEdit3(char const*, float*, int)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x3c1): undefined reference to ImGui::InputText(char const*, char*, unsigned int, int, int ()(ImGuiInputTextCallbackData), void*)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x3ec): undefined reference to ImGui::Button(char const*, ImVec2 const&)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x44a): undefined reference to ImGui::End()' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x476): undefined reference to ImGui::SFML::Render(sf::RenderWindow&)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x48f): undefined reference to ImGui::SFML::Shutdown()' collect2.exe: error: ld returned 1 exit status

I don't know what I'm doing wrong, and if someone has suggestions or tips of a better way of doing all of this, will be apreciated :)

1 Answers1

0

It worked for me by creating a folder called "include" inside the root of the project, putting all .h and .cpp files from imgui and imgui-sfml inside it and running the following 3 line command:

g++ -c ../include/*.cpp -I ../include -L ../include -I C:\SFML\include -L C:\SFML\lib -lsfml-graphics -lsfml-window -lsfml-system -lopengl32

g++ -c ../main.cpp -I ../include -L ../include -I C:\SFML\include -L C:\SFML\lib -lsfml-graphics -lsfml-window -lsfml-system -lopengl32

g++ *.o -o ../build/main.exe -I C:\SFML\include -L C:\SFML\lib -lsfml-graphics -lsfml-window -lsfml-system -lopengl32

Thanks to @drescherjm for the comments, it really helped me!