SDL2_image fails to load libjpeg at runtime

Hi, I am working on a game based on SDL2 and I started to prepare a Linux build to distribute to some testers, but I am struggling to get it to work on systems that don’t have all libraries installed.

The layout of my build is something like this:

mygame/
mygame/game # executable
mygame/data/ # game data
mygame/lib/ # shared libraries (SDL2, SDL2_image, SDL2_ttf, etc…)

I am setting the RPATH of the game executable to lib and that works fine with all libraries, but SDL2_image, which fails to find libjpeg.so.8.

I tried to set the RPATH of SDL2_image to any of the following:

  • .
  • ./
  • lib
  • ./lib

and I tried to do that overwriting the RPATH with patchelf, but also setting the value before compiling the library. No luck either way.

Everything works fine if I launch the executable with a script that sets LD_LIBRARY_PATH=lib, but I would prefer to not do that and let users just launch my executable directly.

Would something like that be possible or is the launch script the only way to get this working?

I encountered a similar issue on windows; sdl_image dlload’s the relevant image library so/dll files and by that point to runtime path is a different context (in my specific case). Try adding an rpath to the sdl2image.so using a tool like elfpatch