1

Using Linux Mint 18 Cinnamon 64-Bit

I am having issues trying to get SFML to work. I am trying to compile from the command line with g++.

My file is /home/joe/Desktop/SFML/test/main.cpp

My SFML Folder is at /usr/lib/SFML-2.4.1

If I run g++ -c main.cpp -I/usr/lib/SFML-2.4.1/include it compiles fine. Then I run g++ main.o -o sfml-app -L/usr/lib/SFML-2.4.1/lib -lsfml-graphics -lsfml-system -lsfml-window -lsfml-audio This had problems before but after using the -L command it works fine now.

howerver when I run ./sfml-app I get the error ./sfml-app: error while loading shared libraries: libsfml-graphics.so.2.4: cannot open shared object file: No such file or directory

Now in the /usr/lib/SFML-2.4.1/lib directory libsfml-graphics.so.2.4 is a symlink with the following chain( all files in this directory.

libsfml-graphics.so -> libsfml-graphics.so.2.4 -> libsfml-graphics.so.2.4.1

So can anyone explain to me why the object file can not be found? Thanks

Joe G
  • 99
  • 1
  • 14
  • You can either use `-rpath/usr/lib/SFML-2.4.1/lib` to tell `ld` to include the full path of the library or create a config file in `/etc/ld.so.conf.d` pointing to the location of the lib then run `ldconfig`. – alvits Jan 07 '17 at 01:20

1 Answers1

0

The problem you're running into is the fact that you're telling the linker where to find the library files/information, but when running the program your system won't know where to find the shared libraries belonging to SFML.

The quickest fix is to create a small shell script to run your program which sets the environment variable LD_LIBRARY_PATH.

Something like this should work (untested):

#!/usr/bin/bash
LD_LIBRARY_PATH=/usr/lib/SFML-2.4.1/bin ./sfml-app

As an alternative, I'd recommend you compile and install SFML from sources. It's not that complicated. The hardest part is determining all dependencies and get those installed first (preferably using your package manager).

It's also possible to install SFML using apt-get, but I'm not 100% sure their version is up to date: sudo apt-get install libsfml-dev

Mario
  • 35,726
  • 5
  • 62
  • 78