使用不同版本的glibc?

时间:2013-04-11 11:12:56

标签: c compilation glibc

我想对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文件以使用glibc中的/mydirectory/glibc-2.17-build

1 个答案:

答案 0 :(得分:1)

使用-L pathname明确指定Barmar在评论中说明的ld路径名。
建议使用静态链接-static或者我认为在执行期间可能存在问题。

实际上我自己解决这个问题的方法是:正常编译和链接源代码,并调用LD_PRELOAD设置为指定版本的共享对象。
http://linux.die.net/man/8/ld.so