0

I am compiling a program with gcc4.9 in ubuntu 18 which comes with glibc 2.27 and trying to run the resulting program on redhat 7.4. Unfortunately, Redhat 7.4 comes with glibc 2.17, so I need to dynamically link my application with that version.

How can I force gcc to use that specific version of glibc?

NOTE: Please study the glibc license before suggesting statically linking.

cheers,es

Goozo
  • 910
  • 2
  • 11
  • 28

1 Answers1

1

There is not just glibc that's a problem but also libgcc and libstdc++ and any other libraries the program might link to.

The proper solution is to setup a RedHat 7.4 chroot and compile your code there.

Goswin von Brederlow
  • 11,875
  • 2
  • 24
  • 42
  • libgcc is not linked dynamically and libstdc++ does not apply with c. Many other libraries are also no problem, if the symbols are not versioned and the api is backward compatible – Ctx Feb 11 '19 at 15:38
  • Not sure what system you have but check `/lib/x86_64-linux-gnu/libgcc_s.so.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=92e0be1929d28508cf9c6d5754c7eb48c12255b3, stripped` – Goswin von Brederlow Feb 11 '19 at 15:46
  • And which of your own-produced binaries link this shared object dynamically on startup? – Ctx Feb 11 '19 at 15:48
  • 1
    Another pitfall is linking glibc statically and thinking that solves the problem. glibc dlopens NSS modules (named services, anything using networking for example) at runtime and if the ABI changed that fails horribly even if glibc was linked static. – Goswin von Brederlow Feb 11 '19 at 15:49
  • @Ctx Not many as most libgcc functions are linked statically. But it can be used. It simply depends on what code you compile. – Goswin von Brederlow Feb 11 '19 at 15:50
  • 1
    If the ABI changed you have completely other problems ;) You mean the API here. Yes, correct, linking glibc is usually not a good idea if you do not know exactly what you are doing. – Ctx Feb 11 '19 at 15:50
  • No, I mean what I said. If the ABI changed. If the API changed your code won't even compile. – Goswin von Brederlow Feb 11 '19 at 15:51
  • ABI is wrong here, if it changed, then dynamic linking at all would not succeed. And how should it not compile, we talk about _dynamic_ libraries here, which mismatch. This issue occurs long time _after_ compilation – Ctx Feb 11 '19 at 15:52
  • Regardless of the nature of any additional problems that might arise the way that OP asks to do it, the suggested solution is indeed the best way forward. – John Bollinger Feb 11 '19 at 16:25