[SDL] Relocable linux binaries (was Re: SDL Linux Help )

Gabriele Greco gabriele.greco at darts.it
Wed Apr 18 03:24:00 PDT 2007


millenomi wrote:
> It won't work, as it will fail the same way it does currently (if the
> BMP he's trying to load is not in the current directory, it'll fail to
> load).
> dirname(argv[0]) is usually the way to go (this does not remove load
> checks as argv[0] can be modified, but one can count on the fact that
> barring bizarre exec()s it'll be correct for users launching the app
> in usual ways).
>   
This problem that seems so "easy" to solve has not a clean solution on
unix systems, you have no way to know the exact path where your
executable lives when your program is launched in different ways (from
desktop, from shell, from a script through an absolute path...)

The guys of autopackage have built a small utility to solve this,
BINRELOC, but it's targeted only at linux (I think it doesn't work for
instance on bsd systems).

Many apps choose to start with a script created in the installation
procedure (this is the case of most apps that use loki installer for
instance), also mozilla/firefox/thunderbird "executables" are really a
script!

So I suggest you to do one of the following things:

1) Insert binreloc in your code
2) Build a wrapper script in the install stage and a .desktop file for
kde/gnome
3) Hardcode the absolute paths of the datafiles (the usual way of unix
projects based on autoconf/automake)
4) Write some code to encode the bmp on your binary and read them
through SDL_rwops

I've used 1, 2 and 4 in different projects :)

---
Bye,
Gabry




More information about the SDL mailing list