c++ - 需要 GLIBC 2.7 版本。使用更高版本的 GLIBC 编译 C++ 代码,同时支持更早的 glibc

标签 c++ gcc centos g++ glibc

这个问题在这里已经有了答案:





Deploying Yesod to Heroku, can't build statically

(4 个回答)


1年前关闭。




我有两台机器

  • RHEL 4机
  • RHEL 6机

  • 现在我有一个可以在 RHEL4 机器上编译的代码,然后在两台机器上运行可执行文件。
    但是如果我在 RHEL6 机器上编译相同的代码,我无法在 RHEL4 机器上运行可执行文件。它会引发错误“需要 GLIBC 2.7 版本”。
    现在我的问题是,RHEL6 机器上的 GLIBC 2.7 已经支持早期版本,并且具有与早期版本相关的 header 。那么我能以某种方式告诉我的 gcc 编译器使用特定的早期版本的 gcc 来编译代码吗? (因为它可以在早期版本上编译......)
    更多信息:

    $readelf -a glibc


    在 RHEL4 机器上显示,
      Addr: 0x0000000000014428  Offset: 0x014428  Link: 4 (.dynstr)
      000000: Rev: 1  Flags: BASE   Index: 1  Cnt: 1  Name: libc.so.6
      0x001c: Rev: 1  Flags: none  Index: 2  Cnt: 1  Name: GLIBC_2.2.5
      0x0038: Rev: 1  Flags: none  Index: 3  Cnt: 2  Name: GLIBC_2.2.6
      0x0054: Parent 1: GLIBC_2.2.5
      0x005c: Rev: 1  Flags: none  Index: 4  Cnt: 2  Name: GLIBC_2.3
      0x0078: Parent 1: GLIBC_2.2.6
      0x0080: Rev: 1  Flags: none  Index: 5  Cnt: 2  Name: GLIBC_2.3.2
      0x009c: Parent 1: GLIBC_2.3
      0x00a4: Rev: 1  Flags: none  Index: 6  Cnt: 2  Name: GLIBC_2.3.3
      0x00c0: Parent 1: GLIBC_2.3.2
      0x00c8: Rev: 1  Flags: none  Index: 7  Cnt: 2  Name: GLIBC_2.3.4
      0x00e4: Parent 1: GLIBC_2.3.3
      0x00ec: Rev: 1  Flags: none  Index: 8  Cnt: 2  Name: GLIBC_PRIVATE
      0x0108: Parent 1: GLIBC_2.3.4
    
    $readelf -a glibc
    在 RHEL6 机器上显示,
    版本定义部分 '.gnu.version_d' 包含 17 个条目:
      Addr: 0x00000031b2a16eb8  Offset: 0x016eb8  Link: 5 (.dynstr)
      000000: Rev: 1  Flags: BASE   Index: 1  Cnt: 1  Name: libc.so.6
      0x001c: Rev: 1  Flags: none  Index: 2  Cnt: 1  Name: GLIBC_2.2.5
      0x0038: Rev: 1  Flags: none  Index: 3  Cnt: 2  Name: GLIBC_2.2.6
      0x0054: Parent 1: GLIBC_2.2.5
      0x005c: Rev: 1  Flags: none  Index: 4  Cnt: 2  Name: GLIBC_2.3
      0x0078: Parent 1: GLIBC_2.2.6
      0x0080: Rev: 1  Flags: none  Index: 5  Cnt: 2  Name: GLIBC_2.3.2
      0x009c: Parent 1: GLIBC_2.3
      0x00a4: Rev: 1  Flags: none  Index: 6  Cnt: 2  Name: GLIBC_2.3.3
      0x00c0: Parent 1: GLIBC_2.3.2
      0x00c8: Rev: 1  Flags: none  Index: 7  Cnt: 2  Name: GLIBC_2.3.4
      0x00e4: Parent 1: GLIBC_2.3.3
      0x00ec: Rev: 1  Flags: none  Index: 8  Cnt: 2  Name: GLIBC_2.4
      0x0108: Parent 1: GLIBC_2.3.4
      0x0110: Rev: 1  Flags: none  Index: 9  Cnt: 2  Name: GLIBC_2.5
      0x012c: Parent 1: GLIBC_2.4
      0x0134: Rev: 1  Flags: none  Index: 10  Cnt: 2  Name: GLIBC_2.6
      0x0150: Parent 1: GLIBC_2.5
      0x0158: Rev: 1  Flags: none  Index: 11  Cnt: 2  Name: GLIBC_2.7
      0x0174: Parent 1: GLIBC_2.6
      0x017c: Rev: 1  Flags: none  Index: 12  Cnt: 2  Name: GLIBC_2.8
      0x0198: Parent 1: GLIBC_2.7
      0x01a0: Rev: 1  Flags: none  Index: 13  Cnt: 2  Name: GLIBC_2.9
      0x01bc: Parent 1: GLIBC_2.8
      0x01c4: Rev: 1  Flags: none  Index: 14  Cnt: 2  Name: GLIBC_2.10
      0x01e0: Parent 1: GLIBC_2.9
      0x01e8: Rev: 1  Flags: none  Index: 15  Cnt: 2  Name: GLIBC_2.11
      0x0204: Parent 1: GLIBC_2.10
      0x020c: Rev: 1  Flags: none  Index: 16  Cnt: 2  Name: GLIBC_2.12
      0x0228: Parent 1: GLIBC_2.11
      0x0230: Rev: 1  Flags: none  Index: 17  Cnt: 2  Name: GLIBC_PRIVATE
      0x024c: Parent 1: GLIBC_2.12
    
    那么有没有办法可以使用 GLIBC 2.3.4 header 在 RHEL6 上编译代码。因为我没有使用 GLIBC 2.3.4 中没有的任何新东西

    最佳答案

    让我们确认一下 RHEL 上的默认 glibc 版本。来自 distrowatch对于 RHEL:

  • RHEL 4 具有 glibc 2.3.4
  • RHEL 6 具有 glibc 2.12

  • I cannot run the executable on RHEL4 machine. It throws an error "GLIBC 2.7 version required".


    自 2.3.4 以来,glibc 中有更新的符号版本在 2.12 中,但在 2.3.4 中没有。所以这是预期的,不会起作用。
    现在我的问题是,RHEL6 机器上的 GLIBC 2.7 已经支持早期版本并且具有与早期版本相关的 header 。
    是的。但是当您使用 glibc 2.12 进行编译时,它可能会使用旧 glibc 版本中没有的符号。

    So can I somehow tell my gcc compiler to use a particular earlier version of gcc to compile the code.


    这是编译器 - gcc - 这就是这里的问题。它是 glibc 库。即使您在带有 glibc 2.12 的系统上安装了较旧的 gcc,您仍然会遇到同样的问题。

    So is there not a way I can compile code on RHEL6 using GLIBC 2.3.4 headers. Since I am not using anything new which was not in GLIBC 2.3.4


    同样,您混淆了很多东西-标题不是问题。它是 glibc 库,特别是它使用的新符号。 “你”可能没有使用任何特定于 glibc 2.12 的东西,但可能会自动引入较新的符号。显然,这就是你的情况。
    我不确定你为什么要这样做。如果您对 RHEL 4 (glibc 2.3.4) 感到满意,那么为什么要在其上编译并在 RHEL 6 上使用它 - 因为较新的 glibc 将具有较旧的符号。

    关于c++ - 需要 GLIBC 2.7 版本。使用更高版本的 GLIBC 编译 C++ 代码,同时支持更早的 glibc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63474548/

    相关文章:

    c++ - 识别 C++ 必要包含的快速方法

    c++ - 使用 libtar 压缩目录

    gcc - 是否可以让 GCC 使用 BOM 源文件编译 UTF-8?

    c - 为什么 asm 由 gcc mov 生成两次?

    centos - rMATS 错误 "unable to access a shared library"

    linux - 临时文件中的 rpmbuild 错误

    c++ - 如何将使用#ifdef编写的支持多种平台的代码移动到库函数中?

    c++ - 无符号与有符号范围保证

    gcc - 编译外部内核模块时如何手动包含.config?

    python - Informix、pyodbc、Centos