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.