Search code examples
linuxsfml

SFML 2.0 Linux installation issue


I am trying without sucess to install SFML 2.0 on a Ubuntu 15.10.

I follow the tutorial:http://www.sfml-dev.org/tutorials/2.0/start-linux.php . I downloaded the Linux archive from the link http://www.sfml-dev.org/download/sfml/2.0/. After that I extracted the archive to /usr/local/ directory on my computer. I try to compile the following code:

#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;
}

When I compile the code with:

g++ main.cpp -o main.o -L/usr/local/lib -lsfml-graphics -lsfml-window -lsfml-system

I get

fatal error: SFML/Graphics.hpp: No such file or directory.

When compiling with

g++ main.cpp -o main.o -I/usr/local/include -lsfml-graphics -lsfml-window -lsfml-system

I get:

/usr/bin/ld: cannot find -lsfml-graphics
/usr/bin/ld: cannot find -lsfml-window
/usr/bin/ld: cannot find -lsfml-system

When I compile the code simply with:

g++ main.cpp -o main.o -lsfml-graphics -lsfml-window -lsfml-system

I am getting:

fatal error: SFML/Graphics.hpp: No such file or directory.

I tried thesudo make install in the SFML2.0 directory, but all I get is install: missing file operand It is really important to install the 2.0 version of SFML. I thought about installing the SFML form the packet manager, but with sudo apt-get install libsfml-dev I would get a newer version of SFML and not the 2.0. Can you tell what should I do to install properly SFML 2.0 on my machine?

Thank you in advance.


Solution

  • fatal error: SFML/Graphics.hpp: No such file or directory. definitely means that your extraction process failed to copy the directory structure over correctly. The folder SFML-2.0 should not be in /usr/local/ .

    1. Extract SFML-2.0 into a directory tar xvf SFML*.tar.bz2
    2. Cd to that directory cd SFML-2.0
    3. Manually copy the contents the directories in SFML-2.0/ (include lib and share) into their respective directories in /usr/local
      1. sudo cp -r share/SFML/ /usr/local/share/
      2. sudo cp -r lib/* /usr/local/lib/
      3. sudo cp -r include/SFML /usr/local/include/

    (Note this will make a mess out of lib)

    Try to recompile main after verifying that the directory SFML-2.0/include/SFML is now located at /usr/local/include/SFML, etc