c - gcc:降低 libc 所需的版本

标签 c linux gcc linker libc

我正在尝试在一些旧的 32 位 RedHat 发行版上运行新编译的二进制文件。
该二进制文件是在运行 libc v2.12 的 CentOS 32 位 VM 上编译的 C(非++)。

RedHat 提示 libc 版本:

error while loading shared libraries: requires glibc 2.5 or later dynamic linker
由于我的程序相当简单,它很可能没有使用 libc 中的任何新内容。

有没有办法降低 libc 版本要求

最佳答案

未经测试的可能解决方案

What is "error while loading shared libraries: requires glibc 2.5 or later dynamic linker"?

The cause of this error is the dynamic binary (or one of its dependent shared libraries) you want to run only has .gnu.hash section, but the ld.so on the target machine is too old to recognize .gnu.hash; it only recognizes the old-school .hash section.

This usually happens when the dynamic binary in question is built using newer version of GCC. The solution is to recompile the code with either -static compiler command-line option (to create a static binary), or the following option:

-Wl,--hash-style=both

This tells the link editor ld to create both .gnu.hash and .hash sections.

According to ld documentation here, the old-school .hash section is the default, but the compiler can override it. For example, the GCC (which is version 4.1.2) on RHEL (Red Hat Enterprise Linux) Server release 5.5 has this line:

$ gcc -dumpspecs
....
*link:
%{!static:--eh-frame-hdr} %{!m32:-m elf_x86_64} %{m32:-m elf_i386} --hash-style=gnu   %{shared:-shared}   ....
                                                                   ^^^^^^^^^^^^^^^^
...

For more information, see here.

关于c - gcc:降低 libc 所需的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12075403/

相关文章:

c++ - 在 C++ 中创建和访问索引文件

linux - 如何通过USB高速传输数据?

python - 如何在 Python 中动态定义类型/类?

android - 识别/proc/*/maps 中的代码段的好方法

gcc - 如何忽略外部库头文件中的 gcc 编译器迂腐错误?

c - 构建内核模块并解决丢失的符号定义

windows - 是否有任何支持 GCC 插件的 mingw-w64 版本?

c - 为什么将 printf 的结果传递给另一个 printf 有效?

c - ipv6 的 UDP 校验和验证 : how to fetch ipv6 source address from auxilliary data

objective-c - xcode 中的 strcpy