【发布时间】:2021-11-03 23:51:05
【问题描述】:
我正在开发一个可以在 CentOS 8 和 CentOS 7 系统上运行的程序。在其中,我使用 gethostbyname 将 DNS 名称解析为 IP 地址。
为了尝试使代码可移植,我正在使用以下命令进行编译:
g++ -static stats-agent.cpp -o stats-agent
当它编译时,我得到以下信息:
/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
现在,当我将二进制文件移至 CentOS 7 系统并尝试运行它时,我得到以下信息:
stats-agent: dl-call-libc-early-init.c:37: _dl_call_libc_early_init: Assertion `sym != NULL' failed.
Aborted
我检查了 glibc、glib-devel 和 glibc-static。我唯一注意到的是 CentOS 8 上的 glibc 版本是 2.28,而 CentOS7 上的版本是 2.17。这可能是造成的吗?我需要编译一个单独的 CentOS 7 和 CentOS 8 二进制文件吗?我正在尝试使其可移植。
【问题讨论】: