$ printf 'int main(){}' | gcc -static -x c - -o hello
$ scp hello vi-server.org:./
hello 100% 565KB 565.2KB/s 00:00
$ ssh -t vi-server.org "./hello; uname -r"
FATAL: kernel too old
sh: line 1: 15378 Segmentation fault ./hello
2.6.18-274.... # can't easily upgrade the kernel
Connection to vi-server.org closed.
How to build static binary that will work on on old systems? I expect static binaries to work even on 2.4.
You need to configure glibc to target the older kernel version. Per http://www.gnu.org/software/libc/manual/html_node/Configuring-and-compiling.html glibc accepts the configure option --enable-kernel=version
where version
is in the form 2.4.20
to target older kernel versions.
You can then link your program statically with gcc -static -nodefaultlibs [...] /path/to/my/libc.a
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With