SFML community forums

General => General discussions => Topic started by: JSB on January 26, 2014, 09:33:53 pm

Title: A quick trick for Linux SFML apps
Post by: JSB on January 26, 2014, 09:33:53 pm
Since I don't want to write: "export LD_LIBRARY_PATH=<path to sfml>/lib && ./sfml-app" into my terminal every time i want to run sfml-app, I did this:
1 Start gedit (go to terminal and type "gedit" then enter)
2 Write:
#!/bin/sh
export LD_LIBRARY_PATH=<path to sfml>/lib && ./sfml-app
3 Save in the same directory as sfml-app.
Title: Re: A quick trick for Linux SFML apps
Post by: Jesper Juhl on January 26, 2014, 10:14:51 pm
If the library location is fixed then an even better option would be to use the linkers -rpath option to put that directory directly into the executable as a path the runtime linker should search for libraries.
Simply do this when linking:

g++ -o my_executable somefile.o someotherfile.o -L/dir/to/search/for/libs/to/link -lsfml-window -lsfml-system -lsomeotherlib -Wl,-rpath=/path/the/runtime/linker/should/search ...other-options-you-may-be-using...

You can then check the resulting executable to make sure that the rpath got set correctly with

readelf -d my_executable | grep RUNPATH

and you should see a line like this:

0x000000000000001d (RUNPATH)            Library runpath: [/path/the/runtime/linker/should/search]

and then you don't need a wrapper script any more.