cgccsdl-3

System can't find libSDL3.so.0 at runtime?


I just installed sdl 3 on my pop-os computer and I wanted to give it a spin. I wrote a small program that creates a window.

The important files in question are at the following locations:

the installed files of sdl 3

When I tried to compile my little program using gcc i got the following result:

compilation result

I do not know what is happening here. The runtime says that the file doesn't exist while it is abundantly clear that it does in fact exist. What's really happening here?

Edit: I was asked to show the output of the file command for the object files.

~$ file /usr/local/lib/libSDL3.so.0
/usr/local/lib/libSDL3.so.0: symbolic link to libSDL3.so.0.1.2
~$ file /usr/local/lib/libSDL3.so
/usr/local/lib/libSDL3.so: symbolic link to libSDL3.so.0
~$ file /usr/local/lib/libSDL3.so.0.1.2
/usr/local/lib/libSDL3.so.0.1.2: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=bb9af1f8d09fc1d0d234188753a4da4eb5b962de, not stripped

Solution

  • So /usr/local/lib is not included in /etc/ld.so.conf. Which means shared libraries in that directory won't be found. Either add the path to it, or add it to LD_LIBRARY_PATH.

    Since adding it to /etc/ld.so.conf (or probably adding an entry in a separate file in /etc/ld.so.conf.d/) requires root access, I'll avoid that.

    Instead, staying on the user side, add the path to LD_LIBRARY_PATH:

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    

    You may want to add that line to your .bashrc or similar file; otherwise you'd have to enter this command in every terminal.


    One last option would be to use a "runpath", but that would require modifying the Makefile to alter the respective build commands. Using a runpath wouldn't be a bad idea, giving that the build command already uses -L/usr/local/lib explicitly, but I'm not sure if you want to go that route. Plus, that requires seeing the Makefile, that is, the relevant build commands, to answer that properly (though it's possible to provide a decent option without it).