0

I am developing a program that will run on both CentOS 8 and CentOS 7 systems. In it, I am using the gethostbyname to resolve DNS names to IP addresses.

To try and make the code portable, I am compiling using the following command:

g++ -static stats-agent.cpp -o stats-agent

When it compiles I get the following:

/tmp/ccVDW5ph.o: In function `main':
stats-agent.cpp:(.text+0x45c): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Now when I move the binary over to the CentOS 7 system and I try and run it, I get the following:

stats-agent: dl-call-libc-early-init.c:37: _dl_call_libc_early_init: Assertion `sym != NULL' failed.
Aborted

I have checked the glibc, glib-devel and, just incase, glibc-static. The only thing I noticed is version of glibc on CentOS 8 is 2.28 and the version on CentOS7 is 2.17. Could that be causing it? Will I have to compile a separate CentOS 7 and CentOS 8 binary? I am trying to make it portable.

1 Answers1

0

To try and make the code portable, I am compiling using the following command

Don't. Contrary to popular belief, fully-static Linux binaries are less portable -- only guaranteed to work if the exact same version of GLIBC is installed at runtime, as the one used during the build. That's what the warning is telling you. See also this answer.

Could that be causing it?

It could, and does.

Will I have to compile a separate CentOS 7 and CentOS 8 binary?

Only if you insist on fully-static linking.

You could build your binary using dynamic libc.so.6 on CentOS 7 (or in a chroot, or a docker container, or a VM), and it will work fine on CentOS 8 as well.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362