mercredi 1 juillet 2015

Compile C++11 with modern g++ for old Linux (2.6.16)

I've written a C++11 program (and use C++11 features extensively -- it is not feasible to remove the dependency). For development I am using a

Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 GNU/Linux 
g++ (GCC) 4.9.2

box. I want to run it on an old

Linux 2.6.18-371.6.1.el5 #1 SMP Wed Mar 12 14:06:47 CDT 2014 i686 i686 i386 GNU/Linux.
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50)

box.

The following seems promising

g++ file.cpp -std=c++11 -static -Os -m32

The resulting file has

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

and segfaults when I try to run it (on the old installation).

I have no admin rights etc on either machine. Is there a quick solution (quicker than going home and rebuilding glibc with --enable-kernel=2.6.0 on my laptop)?

[I know there are old questions on this (and I have looked at them), but I'm hoping for something that doesn't require rebuilding stuff or installing virtual images etc.]

Aucun commentaire:

Enregistrer un commentaire