Home:ALL Converter>Compiling on CentOS 8 for CentOS 7

Compiling on CentOS 8 for CentOS 7

Ask Time:2021-09-07T11:42:37         Author:chris-p-tech

Json Formatter

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.

Author:chris-p-tech,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69082168/compiling-on-centos-8-for-centos-7
yy