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

Author Topic: SFML on Ubuntu 12.04  (Read 4736 times)

0 Members and 1 Guest are viewing this topic.

TheGreekGeek

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
SFML on Ubuntu 12.04
« on: June 12, 2014, 10:36:04 pm »
Hello all. I have a problem to get SFML v2.1 get working with my Ubuntu 12.04 LTS Operating System. I've tried a lot of tutorials on the net but it won't work properly (or i'm just too dumb). The problem is the following:
- I've installed all the packages from http://onlyakiss.net/2013/04/how-to-install-sfml-2-0-into-ubuntu-12-04/ and now i have a folder with the compiled binaries of SFML on my Desktop. There were no problems in compiling it so i think it should be fine. Now i used the following code-fragment for a quick test (i also did ldconfig to update the paths to the files):
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

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

    return 0;
}

compiled it with the terminal and g++ i also added -I<path> and so on but it won't compile. The error messages were:

/usr/bin/ld: error: cannot find -lsfml-graphics
/usr/bin/ld: error: cannot find -lsfml-window
/usr/bin/ld: error: cannot find -lsfml-system
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::String::String(char const*, std::locale const&)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::CircleShape::CircleShape(float, unsigned int)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::Color::Green'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::Shape::setFillColor(sf::Color const&)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::Window::close()'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::Window::pollEvent(sf::Event&)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::RenderTarget::clear(sf::Color const&)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::RenderStates::Default'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::Window::display()'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::Window::isOpen() const'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::RenderWindow::~RenderWindow()'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::RenderWindow::~RenderWindow()'
Test_SFML.o:Test_SFML.cpp:function main: error: undefined reference to 'sf::RenderWindow::~RenderWindow()'
Test_SFML.o:Test_SFML.cpp:function sf::CircleShape::~CircleShape(): error: undefined reference to 'vtable for sf::CircleShape'
Test_SFML.o:Test_SFML.cpp:function sf::CircleShape::~CircleShape(): error: undefined reference to 'vtable for sf::CircleShape'
Test_SFML.o:Test_SFML.cpp:function sf::CircleShape::~CircleShape(): error: undefined reference to 'sf::Shape::~Shape()'
collect2: ld returned 1 exit status



so it looks to me, that there is no "connection" between my file and the library of SFML, but i do not now how to fix it. Any help would be appreciated. Thanks! Sorry this is my first post.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML on Ubuntu 12.04
« Reply #1 on: June 12, 2014, 10:47:36 pm »
Have you tried the official tutorial? http://www.sfml-dev.org/tutorials/2.1/start-linux.php

TheGreekGeek

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: SFML on Ubuntu 12.04
« Reply #2 on: June 12, 2014, 11:00:13 pm »
Have you tried the official tutorial? http://www.sfml-dev.org/tutorials/2.1/start-linux.php

Yes I tried it 2 or 3 times, it gives me exactly the same error output, it compiles but linking the executable file with the library of SFML it gives the same error log.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6288
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML on Ubuntu 12.04
« Reply #3 on: June 12, 2014, 11:11:00 pm »
Well, as the message says, the linker cannot find the libraries. So you didn't install SFML properly or didn't specify the library path (if necessary) in the linker flags.

How have you installed SFML? Maybe you could try to build it from source, also to have the latest bugfixes and features. You would then have to read the CMake tutorial.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML on Ubuntu 12.04
« Reply #4 on: June 12, 2014, 11:14:45 pm »
ldconfig only tells the runtime linker (ld.so) where to look for libraries. It doesn't do anything for the compile-time linker.
You need to tell the linker where to find the SFML libraries - and based on the errors you post, you are not doing that.

TheGreekGeek

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: SFML on Ubuntu 12.04
« Reply #5 on: June 12, 2014, 11:25:13 pm »
Well, as the message says, the linker cannot find the libraries. So you didn't install SFML properly or didn't specify the library path (if necessary) in the linker flags.

How have you installed SFML? Maybe you could try to build it from source, also to have the latest bugfixes and features. You would then have to read the CMake tutorial.
I build a version from source with cmake, but the file was not from SFML directly it was from LaurentGomila if anybody knows him (Tutorial). I will try it now with the package from the official site of SFML.

TheGreekGeek

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: SFML on Ubuntu 12.04
« Reply #6 on: June 12, 2014, 11:27:49 pm »
ldconfig only tells the runtime linker (ld.so) where to look for libraries. It doesn't do anything for the compile-time linker.
You need to tell the linker where to find the SFML libraries - and based on the errors you post, you are not doing that.
Oh ok, i didn't knew that, so i have to tell the compiler by typing g++ -c <file> -I<path to SFML> where to search for SFML or am I wrong?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML on Ubuntu 12.04
« Reply #7 on: June 13, 2014, 07:51:24 am »
Oh ok, i didn't knew that, so i have to tell the compiler by typing g++ -c <file> -I<path to SFML> where to search for SFML or am I wrong?

-I tells it where to look for header files during compilation.  You may also need an -L to tell it where to look for the actual libraries during linking, since it can't seem to find them on its own.

Where did you install the SFML libs?  As mentioned above this shouldn't be a issue if they're in a standard location.  And what is the *exact* g++ command you're currently running that doesn't work?

TheGreekGeek

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: SFML on Ubuntu 12.04
« Reply #8 on: June 13, 2014, 09:07:09 am »
Oh ok, i didn't knew that, so i have to tell the compiler by typing g++ -c <file> -I<path to SFML> where to search for SFML or am I wrong?

-I tells it where to look for header files during compilation.  You may also need an -L to tell it where to look for the actual libraries during linking, since it can't seem to find them on its own.

Where did you install the SFML libs?  As mentioned above this shouldn't be a issue if they're in a standard location.  And what is the *exact* g++ command you're currently running that doesn't work?

I've my binaries on my Desktop at the moment. But now it works! I used  g++ -c main.cpp and g++ main.cpp -o executable.o -LSFML2.1-build/lib -lsfml-graphics -lsfml-window -lsfml-system. But could you tell me, what the stadard location for SFML is? Thanks for any help :)  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML on Ubuntu 12.04
« Reply #9 on: June 13, 2014, 09:27:24 am »
Quote
But now it works! I used  g++ -c main.cpp and g++ main.cpp -o executable.o -LSFML2.1-build/lib -lsfml-graphics -lsfml-window -lsfml-system.
Isn't it exactly what the official tutorial shows? :-\

Quote
I build a version from source with cmake, but the file was not from SFML directly it was from LaurentGomila
Repositories under LaurentGomila are the official ones.
Laurent Gomila - SFML developer

TheGreekGeek

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: SFML on Ubuntu 12.04
« Reply #10 on: June 13, 2014, 09:42:42 am »
Quote
But now it works! I used  g++ -c main.cpp and g++ main.cpp -o executable.o -LSFML2.1-build/lib -lsfml-graphics -lsfml-window -lsfml-system.
Isn't it exactly what the official tutorial shows? :-\

Quote
I build a version from source with cmake, but the file was not from SFML directly it was from LaurentGomila
Repositories under LaurentGomila are the official ones.

Yes. But it has never worked before, I assume that i compiled SFML wrong or something like that. But somehow it won't work for another file i would like to compile (the example works now) I have SFML/Graphics bounded to another file, and exactly the same commands won't work. Here it says SFML/Graphics not found even I have it on my Desktop like the previous example. Sorry for the trouble i'm quite new in binding libraries and stuff to c++ files, it was never shown in the lecture how to do it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML on Ubuntu 12.04
« Reply #11 on: June 13, 2014, 12:09:27 pm »
Again, the tutorial has the answer: you must add -I<path-to-sfml-headers> to your compiler command line. Seriously, just do what the tutorial shows. It works.
Laurent Gomila - SFML developer