I always wonder with that, how are SFML's dependencies handled? Can I compile this on Debian and then really run it on Ubuntu, Arch and Gentoo? What if runtime libs differ?
I have tried compiling an application in the past that ran on both ubuntu and arch linux. I never really knew which dependencies to ship so I just copied the ones that were asked for when starting the app. The result was that a year later on a different system it sometimes missed some library.
So I decided to take a more detailed look into this today and these are my findings (some information may be incorrect, these are simply my observations). Since I do not have ubuntu I used docker from arch linux.
There are 2 problems with distributing the executable:
1) You can only run the executable on newer systems (or the same) as the one you compile with.
You cannot ship libc with your application. If you attempt to do this then you get an error like this:
./Game: relocation error: /mnt/lib/libc.so.6: symbol _dl_find_dso_for_object, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference
Shipping ld-linux-x86-64.so isn't possible (adding it to the lib doesn't do anything).
But if you do not ship libc.so then it will use the one from the operating system. Since libc is backwards compatible this is fine when the executable was created with an older libc version. But it the libc version used to compile the programs and libraries is newer then you will be greeted with an error like this:
./Game: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.18' not found (required by /mnt/lib/libstdc++.so.6)
2) Not all dependencies should be shipped.
When copying all dependencies that ldd shows, you will either get a similar GLIBC_PRIVATE error that I showed earlier or it will simply lead to a segfault (debugger says the crash happens in libc.so).
The following libraries could NOT be included with my application:
- libc.so.6
- libdl.so.2
- libGL.so.1
- libpthread.so.0
- libdbus-1.so.3
- libgcc_s.so.1
- libm.so.6
- libstdc++.so.6
A third problem might be 32bit vs 64bit, I didn't test with that but I doubt that my 64bit app will just run on a 32bit linux.
The following test program should run out of the box on anything newer than ubuntu 14.04 (only tested running on arch linux):
https://www.dropbox.com/s/jacna15uyttfwov/linux64-binary-test.tar.gz?dl=1This is the code that I have in my
cmake script to set the RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib/:$$ORIGIN/lib/")