2013-04-11 81 views
1

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

/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

+0

“ld”的'-L'选项将一个目录添加到库搜索列表中。 – Barmar 2013-04-11 11:15:23

+0

嗯...不会使用一些其他glibc比系统一旦导致问题一旦可执行文件链接一些*其他*库(反过来链接系统libc)? – DevSolar 2013-04-11 11:22:45

回答

1

使用-L pathname显式指定路径名为ld,正如Barmar在评论中所述。
建议使用静态链接-static或者我认为在执行过程中可能会出现问题。

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