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

Author Topic: A quick trick for Linux SFML apps  (Read 3068 times)

0 Members and 1 Guest are viewing this topic.

JSB

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
A quick trick for Linux SFML apps
« 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.
« Last Edit: January 26, 2014, 09:43:55 pm by JSB »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: A quick trick for Linux SFML apps
« Reply #1 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.