【问题标题】:Using a different version of glibc?使用不同版本的 glibc?
【发布时间】:2013-04-03 13:26:37
【问题描述】:

我想对glibc 库进行一些修改。第一步是在我编译程序时能够使用特定的版本。我在 ubuntu 12.10 下,我的目录是:

/mydirectory/glibc-2.17 (where I have extracted the last version from the website)
/mydirectory/glibc-2.17-build (where I have executed the configure and make command)
/mydirectory/test/helloworld.c (where I have my helloworld program)

helloworld.c 如下:

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
   char glibc[256] = "xxxx"; /* How to detect the glibc version here ? */
   printf("hello, world\n");
   printf("glibc version = %s\n", glibc);
   return 0;
}

首先如何打印glibc 的版本? (我认为 glibc 中有一个宏/常量)。

其次,我应该使用什么命令行来编译我的helloworld.c 文件以使用/mydirectory/glibc-2.17-build 中的glibc

【问题讨论】:

  • -L 选项到ld 将目录添加到库搜索列表。
  • Hmm... 一旦可执行文件链接了一些 other 库(该库又链接到系统 libc )?

标签: c compilation glibc


【解决方案1】:

正如 Barmar 在评论中所说,使用 -L pathname 明确指定 ld 的路径名。
建议使用静态链接-static,否则我认为执行过程中可能会出现问题。

其实我自己对这个问题的解决方案是:像平常一样编译和链接源代码,然后调用 LD_PRELOAD 设置为您指定的共享对象版本。
http://linux.die.net/man/8/ld.so

【讨论】:

    猜你喜欢
    • 2012-06-01
    • 2014-12-23
    • 1970-01-01
    • 2020-12-07
    • 2012-06-21
    • 2018-07-21
    • 2019-08-06
    • 2020-10-12
    • 1970-01-01
    相关资源
    最近更新 更多