4

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?

linuxbuild
  • 15,508
  • 6
  • 57
  • 86
user2188453
  • 1,055
  • 1
  • 10
  • 24
  • 1
    I'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
  • 1
    If 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 Answers2

4

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. 1.8e9-where's-my-share m.
  • 102,958
  • 14
  • 123
  • 225
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
  • 216,767
  • 17
  • 275
  • 509