Errors on compile, Clang and TGUI...

Started by Littleclaws, 25 April 2015, 01:58:25


Hey y'all

So I stumbled upon TGUI and thought it's the thing I need, so after compiling it (as a static library), copying the login example to my setup and running : clang++ src/main.cpp -o a.out -ltgui-s -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -std=c++0x
I get greeted with this ... (I also tried -std=c++11)
Error in Pastebin because if it wasn't the case, it would exceed the maximum allowed length
And that was not even the full error message ... the rest gets clipped out by the terminal character limit

Any ideas how to fix?
Thank you for reading and have a nice day!
clang -v
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/5.1.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.2
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.1.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.1.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.1.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9


Just tried using g++, it still gives me errors  :-\
I am on Ubuntu by the way ...


QuoteAnd that was not even the full error message ... the rest gets clipped out by the terminal character limit
I'm actually going to need the first lines to help, because the lines you posted don't contain much information.

You should add something like "> output.txt" behind your command to redirect it to a file. That way you won't lose the top part of the error if it is too long.


Here's the complete log ...
I fixed it by adding these flags to my line:
-std=c++11 -stdlib=libc++ -nostdinc++ -Ic++
So now the full line is...
clang++ src/main.cpp -o a.out -std=c++11 -stdlib=libc++ -nostdinc++ -Ic++ -Lbin -Ilib/bin -Ilib/src -lmysql-s -ltgui-s -lsfml-graphics-s -lsfml-window-s -lsfml-system-s
Also built libcxx from scratch, But idk if that had any effects as my gcc installation is fairly new

Edit 2: In version 0.7-dev, Adding #include <SFML/Window.hpp> as mentionned in the example, brings up an error #include <ostream> file not found ... just to let you know.

Edit 3: Now seems like clang doesn't find it's basic headers, seems like it's an old bug with the libc++ version I have ('string' file not found)
Seems like sudo apt-get upgrade libc++-dev did not fix it ... 


QuoteHere's the complete log ...
Those errors mean that you are using tgui 0.7-dev with the example code from 0.6.

QuoteAdding #include <SFML/Window.hpp> as mentionned in the example
What example? When using TGUI you don't have to include SFML manually since the tgui header will do that for you.

Quotebrings up an error #include <ostream> file not found
That sounds like something is seriously corrupted. The <ostream> header is part of the std library so you must have it on any working system.

I think there is something seriously wrong with your system, you might want to try removing and reinstalling gcc and clang and associated packages. You should be able to use tgui like:
clang++ -std=c++11 Scalable.cpp -ltgui -lsfml-graphics -lsfml-window -lsfml-system


Yeah, I am currently re-installing llvm. clang and libc++ from scratch, hopefully I'll work this time...


After copying the include and bins from libcxx and libcxxabi, I still get errors  :'(
clang++ src/main.cpp -o a.out -std=c++11 -nostdinc++ -lc++ -Lbin -Ilib/bin -Ilib/src -Ilib/cxx -lmysql-s -ltgui-s -lsfml-graphics-s -lsfml-window-s -lsfml-system-s
A lot less errors and warnings, but still ...
I think it's the fact that the examples are outdated and that you don't create objects like that anymore or something like that ...
All the errors are constructor ones ...

Edit 2: Just read your last message, and hey I'm stupid
Checking out the TGUI folder, it comes with it's own examples,
I got it working ... Welp, thanks for answering me and have a nice day!


Edit: nevermind this post, I didn't read your edit.

Quotesrc/main.cpp:11:19: error: no matching constructor for initialization of
      'tgui::Label::Ptr' (aka 'shared_ptr<tgui::Label>')
        tgui::Label::Ptr labelUsername(gui);
You are still using example code for 0.6 while you have tgui 0.7-dev installed.

In both versions tgui::Label::Ptr exists, but only in v0.7 is it of type shared_ptr<tgui::Label>. In v0.6 I had my own smart pointer class which allowed me to define my own constructor which could take the gui as parameter.

You should try with the following code (you will have to edit the filenames of font, images and themes for the code to actually run).
Code (cpp) Select
#include <TGUI/TGUI.hpp>

void login(tgui::EditBox::Ptr username, tgui::EditBox::Ptr password)
    std::cout << "Username: " << username->getText().toAnsiString() << std::endl;
    std::cout << "Password: " << password->getText().toAnsiString() << std::endl;

void loadWidgets( tgui::Gui& gui )
    // Get a bound version of the window size
    // Passing this to setPosition or setSize will make the widget automatically update when the view of the gui changes
    auto windowWidth = tgui::bindWidth(gui);
    auto windowHeight = tgui::bindHeight(gui);

    // Create the background image (picture is of type tgui::Picture::Ptr or std::shared_widget<Picture>)
    auto picture = tgui::Picture::create("../xubuntu_bg_aluminium.jpg");
    picture->setSize(tgui::bindMaximum(800, windowWidth), tgui::bindMaximum(600, windowHeight));

    // Create the username edit box
    auto editBoxUsername = tgui::EditBox::create("../../widgets/Black.conf");
    editBoxUsername->setSize(windowWidth * 2/3, windowHeight / 8);
    editBoxUsername->setPosition(windowWidth / 6, windowHeight / 6);
    gui.add(editBoxUsername, "Username");

    // Create the password edit box (we will copy the previously created edit box)
    auto editBoxPassword = tgui::EditBox::copy(editBoxUsername);
    editBoxPassword->setPosition(windowWidth / 6, windowHeight * 5/12);
    gui.add(editBoxPassword, "Password");

    // Create the login button
    auto button = tgui::Button::create("../../widgets/Black.conf");
    button->setSize(windowWidth / 2, windowHeight / 6);
    button->setPosition(windowWidth / 4, windowHeight * 7/10);

    // Call the login function when the button is pressed
    button->connect("pressed", login, editBoxUsername, editBoxPassword);

int main()
    // Create the window
    sf::RenderWindow window(sf::VideoMode(400, 300), "TGUI window");
    tgui::Gui gui(window);

        // Load the font

        // Load the widgets
    catch (const tgui::Exception& e)
        std::cerr << "Failed to load TGUI widgets: " << e.what() << std::endl;
        return 1;

    // Main loop
    while (window.isOpen())
        sf::Event event;
        while (window.pollEvent(event))
            // When the window is closed, the application ends
            if (event.type == sf::Event::Closed)

            // When the window is resized, the view is changed
            else if (event.type == sf::Event::Resized)
                window.setView(sf::View(sf::FloatRect(0, 0, event.size.width, event.size.height)));

            // Pass the event to all the widgets


        // Draw all created widgets


    return EXIT_SUCCESS;


I tried compiling that and it returns me ...
g++ src/main.cpp -o a.out -Lbin -Ilib/bin -Ilib/src -Ilib/cxx -std=c++11 -lpthread -lGL -lGLU -ltgui-s -lsfml-graphics -lsfml-window -lsfml-system
/usr/bin/ld: bin/libtgui-s.a(Gui.cpp.o): undefined reference to symbol 'glEnable'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/ error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [default] Error 1

No compiling errors but GL is giving me troubles  :-[
Thank you for the help @texus


You are already linking to opengl so I suspect the problem is in the library order. The dependencies belong behind the library in gcc. Just like you have tgui before sfml and sfml-window before sfml-system, you should put GL after tgui. This does not matter for dynamic linking, but you are linking to tgui statically.

This is unrelated but you should be aware of one thing: you should always link tgui in the same way as sfml. I have never tried static linking on linux so I can't tell if it gives problems or not, but on windows linking like you are doing leads to linking errors or crashes. Either link both tgui and sfml dynamically or link both of them statically. I would suggest dyamic linking because linking statically to sfml on linux can be a pain.


I have taken the official SFML 2.2 static binaries for Linux 64bits and recompiled TGUI-0.7 as a static library and compiled but it's giving me this :(
g++ src/main.cpp -o a.out -Lbin -Ilib/bin -Ilib/src -std=c++11 -ltgui -lsfml-graphics -lsfml-window -lsfml-system
bin/ undefined reference to `sf::ConvexShape::ConvexShape(unsigned long)'
bin/ undefined reference to `sf::CircleShape::CircleShape(float, unsigned long)'
bin/ undefined reference to `sf::RenderTarget::draw(sf::Vertex const*, unsigned long, sf::PrimitiveType, sf::RenderStates const&)'
bin/ undefined reference to `sf::ConvexShape::setPoint(unsigned long, sf::Vector2<float> const&)'
collect2: error: ld returned 1 exit status
make: *** [default] Error 1

I don't get what's wrong with my code