Distributing a statically linked ELF 32bit Binary

2019-07-06 17:22发布

问题:

My team is ready to release the first version of our Linux program and would like to do so in the easiest possible manner (for users).

The program needs no external files, no install, and is statically linked.

ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.15, not stripped

My question is whether such a binary will run on most Linux platforms (Ubuntu, Redhat, OpenSuse, etc)?

I'm also a bit concerned about the part where it says 'for GNU/Linux 2.6.15', does this mean that they need kernel 2.6.15 or higher?

回答1:

Full statically linked programs are not recommended anymore.

The portability layer moved from kernel calls into the basic libraries (remember the pthread desaster and the problems with LinuxThreads <-> NPTL threads?).

Follow the LSB 4.0 standard. Trust in the existence of the libraries mentioned there (not so many unfortunately) and bundle all the other shared libraries with your application. There is a linker flag - i think it was -L - where you can set a ldd path which has precedence over all other settings during shared library loading so your libs are always loaded first.

Make sure that all libraries only call LSB approved API functions (or have a look on the LSB website and see how serious a non supported LSB API call is - sometimes you simply can't avoid it and they have a list of Distributions that support this call).

This is the recommended way to deliver binary executables. And it still sucks a lot on Linux compared to Windows/MacOSX.