2

I'm trying to integrate SFML and TGUI libraries into my C++ projects. While SFML works perfectly, I’m having trouble with TGUI.

I followed the installation instructions on the TGUI website carefully—adding the necessary directories and setting the appropriate properties in Visual Studio. However, I get an error when running the following code:

#include <SFML/Graphics.hpp>
#include <TGUI/TGUI.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI Example");
    tgui::Gui gui(window);

    // Other GUI setup code here

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            gui.handleEvent(event);
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        gui.draw();
        window.display();
    }

    return 0;
}

I’ve double-checked that the TGUI library is included correctly, but I’m at a loss for what could be going wrong.

Does anyone have any suggestions or solutions?

I tried pretty much everything i could. Double-Checking if i pasted the right directories (i did according to the TGUI installation guide) and also the visual studio project include properties (which also are correct) but this error doesnt seem to go away.

Edit: I checked, and the error message is coming from IntelliSense in Visual Studio. The exact error message is:

Severity: Code  
Description: Namespace "tgui" does not have a member "Gui".  
Project: PhyEng  
File: C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp  
Line: 7

The build log says the following at the end:

The build started at 17:37...
1>------ Build started: Project: PhyEng, Configuration: Debug x64 ------
1>Main.cpp
1>C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp(9,11): error C2039: 'Gui' is not a member of 'tgui'.
1>    C:\Users\Admin\Desktop\RandProj\PhyEng\include-tgui\TGUI\Widgets\VerticalLayout.hpp(32,30):
1>    See declaration of 'tgui'
1>C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp(9,11): error C2065: 'Gui': undeclared identifier
1>C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp(9,15): error C2146: syntax error: missing ';' before identifier 'gui'
1>C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp(9,15): error C3861: 'gui': identifier not found.
1>C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp(15,5): error C2065: 'gui': undeclared identifier
1>C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp(20,5): error C2065: 'gui': undeclared identifier
1>C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp(34,13): error C2065: 'gui': undeclared identifier
1>C:\Users\Admin\Desktop\RandProj\PhyEng\PhyEng\Main.cpp(38,9): error C2065: 'gui': undeclared identifier
1>The build of the project 'PhyEng.vcxproj' is complete -- ERROR.
16
  • 4
    The compiler is giving me Are your sure this is the compiler and not IntelliSense? Please post the complete verbatim error message in a code block. Commented Oct 31, 2024 at 16:24
  • 1
    Does your code actually compile? You can ignore Intellisense errors if you know they are wrong. Commented Oct 31, 2024 at 16:32
  • 1
    Yepp, yall right! I updated the post now. It indeed was from Intellisense Commented Oct 31, 2024 at 16:32
  • 1
    Namespace tgui indeed does not have a member Gui. You may need tgui::GuiSFML, which also requires some additional includes to pull sfml backend. Commented Oct 31, 2024 at 16:57
  • 1
    @drescherjm i added the whole build log n ow Commented Oct 31, 2024 at 17:11

1 Answer 1

3

From the TGUI documentation: https://tgui.eu/documentation/0.9/classtgui_1_1GuiSFML.html and the example SFML program https://tgui.eu/tutorials/latest-stable/backend-sfml-graphics/ you appear to be missing an include.

Please add:

#include <TGUI/Backend/SFML-Graphics.hpp>

to your includes.

A minimal TGUI program that uses SFML as the GUI backend would be the following:

#include <TGUI/TGUI.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>

int main()
{
    sf::RenderWindow window{{800, 600}, "TGUI example - SFML_GRAPHICS backend"};
    tgui::Gui gui{window};
    gui.mainLoop(); // See below for how to use your own main loop
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.