How to install SFML in ubuntu?

15k views Asked by At

I downloaded SFML, then I copied all its headers in usr/local/include/ and copied all its libraries in usr/local/lib/ .

I have a file named main.cpp in Desktop which I want to compile.

First I did this :-

g++ -c main.cpp

After that when I try to do this :-

g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system

It gives me :-

/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_action@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_list_entry_get_next@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_unref@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_list_entry_get_name@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_unref@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_unref@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_new@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_receive_device@LIBUDEV_183'
/usr/local/lib/libsfml-graphics.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_devnode@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_enable_receiving@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_new@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_get_fd@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_unref@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_property_value@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_filter_add_match_subsystem_devtype@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_get_list_entry@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_scan_devices@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_enumerate_add_match_subsystem@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_syspath@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_sysattr_value@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_monitor_new_from_netlink@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_new_from_syspath@LIBUDEV_183'
/usr/local/lib/libsfml-window.so: undefined reference to `udev_device_get_parent_with_subsystem_devtype@LIBUDEV_183'

I have installed all these required dependencies correctly : https://github.com/SFML/SFML/wiki/Tutorial%3A-Installing-SFML-dependencies

Have I missed any required step ?

2

There are 2 answers

0
Jay Kominek On

Just because you're got the dependencies installed doesn't mean you're making use of them.

undefined reference to `udev_device_get_action@LIBUDEV_183'

The mention of udev and LIBUDEV suggest to me that you need to link against libudev. Try adding -ludev to your command line.

If you pasted all of the link errors, then that might actually take care of it. If you just pasted the first 20, then there might be other libraries that need to be linked in. Look at the missing symbols, figure out what libraries they're from, and add them.

/usr/local/lib/libsfml-graphics.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'

Not sure what the deal is there. You might need to link against the C++ libraries?

Anyways, you should take a look at the instructions for setting up makefiles for your SFML project: https://github.com/SFML/SFML/wiki/Tutorial%3A-Build-your-SFML-project-with-CMake

0
Yanjan. Kaf. On

To Install it in Ubuntu first you run following command in your terminal -

sudo apt-get install libsfml-dev

make sure you already have compiler (GCC) and make if not then install it using

sudo apt-get install build-essential

Then to test this out create a simple SFML app like this

#include <SFML/Graphics.hpp>

int main(int argc, char const *argv[])
{
    sf::RenderWindow window(sf::VideoMode(200,200), "Hello From SFML");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Magenta);

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

Now create a makefile in the repo same as main.cpp

compile:./main.cpp
    g++ -c ./main.cpp
    g++ main.o -o app -lsfml-graphics -lsfml-window -lsfml-system

run:
    ./app

now to compile it run the following command

make compile

and finally to run this run following command

make run