Search code examples
c++ubuntusdlsdl-2

What are the binaries files needed to my SDL2 program so it works in another computer without SDL2 installed


What binary files I have to ship with my SDL2-based program so it can works on another computer without SDL installed?

Libraries required for my program:

iostream
SDL2/SDL.h
SDL2/SDL_image.h
ctime
cstdlib

Binary files which I already tried to use:

libSDL2.so
libSDL2-2.0.so.0.8.0
libSDL2_image.so
libSDL2_image-2.0.so.0.2.1

PS: I'm testing whether my program package works or not with a bootable Xubuntu pen drive


Solution

  • The short answer is "use ldd". The long answer follows.

    ldd ./your_program will show recursive list of all runtime dependencies (yours and dependencies of every library you use, and their dependencies, ...).

    readelf -d ./your_program | grep NEEDED will show your direct dependencies (only ones your program actually links against - doesn't necesserily mean you can copy only those).

    LD_DEBUG envvar could be utilised to trace what libraries are loaded at runtime (e.g. with dlopen).

    If you target one specific distribution it may be siplier to build package with dependencies specified so e.g. apt would install SDL for you.

    Next big question is where did you get your SDL. Many distributions disables SDL dynamic loaders so it wouldn't run without e.g. libX11, wayland, libXi, pulseaudio, ... It is very much ok for that distribution to do so, as it was never intended you'll just copy some libraries to another machine. If you build it yourself you can have much less direct dependencies and SDL will try to dlopen whateven it needs. SDL2_image is probably easier example - it could depend on libjpeg, libpng, libz, ..., it is possible you don't need some formats but if you have linked with that libraries you can't run without them.

    Consider what libraries you could consider 'always there'. E.g. it makes no sense to carry libX11 or libc and many others. This part is shared for all OS - you can't get half of OS with your program, for multiple reasons.

    To sum it up, use SDL build with dynamic loading enabled (I think it is default for quite a time now), copy SDL/SDL_image, use LD_LIBRARIES_PATH to set your libs location, verify list with ldd, and you should be fine. Do not copy libc, libstdc++, libpthread, libm.