If I get some C++ code built by, lets say, GCC 4.8 on Ubuntu, the code has no GUI/interface, only call standard Linux libraries, then can the binary run on RHEL 5/6, with much older GCC flawlessly?
Asked
Active
Viewed 538 times
4
-
1I'm not a Unix expert, but I think if you link everything statically and your app doesn't use ubuntu-specific API, it should work. Best way to know is to try :) – DarkWanderer Dec 27 '13 at 11:49
-
1If it's statically linked then probably; if it's dynamically linked then probably not. – Elliott Frisch Dec 27 '13 at 16:57
-
You'd better to compile your program on older Ubuntu for better compatibility because most of the system libraries, compilers and other tools trying to be backward-compatible. – linuxbuild Oct 22 '16 at 21:29
2 Answers
5
Normally it can't. It will complain about libc being too old, for one.
If you statically link with libstdc++ and carefully avoid newer glibc features, you may be able to get away with it. The latter is not always possible though. Static linking with libc is not officially supported and may work or not work for you.

n. m. could be an AI
- 112,515
- 14
- 128
- 243
-
It is actually possibly to just rebuild an older version of libc with GCC 4.8, run patchelf (http://nixos.org/patchelf.html) and everything might be OK. – Dec 27 '13 at 18:02
-
@skwllsp copying libc over from the target system often works too. – n. m. could be an AI Dec 27 '13 at 18:49
-
1Are you sure? Take a look at this: http://stackoverflow.com/a/851229/184968? Do you mean copying everything include ld-linux.so.2? – Dec 27 '13 at 19:17
-
@skwllsp I don't guarantee it will work, but I think copying /lib abd /usr/lib over can work. – n. m. could be an AI Dec 27 '13 at 20:10
2
The issue is probably more Glibc than libstdc++
(which you can indeed link statically) or GCC itself.
You could use an alternative Libc, such as MUSL libc (which is supposed to be more friendly with static linking)
Also, there might be some kernel dependencies.

Basile Starynkevitch
- 223,805
- 18
- 296
- 547