首页 > *nix技术, 应用程序 > Linux glibc源码升级

Linux glibc源码升级

2013年2月6日 发表评论 阅读评论 1,149 次浏览

1,准备工作:准备好系统,下载好glibc源代码,确保系统提供的gcc,make等满足glibc的要求(glibc的INSTALL文件内有明确说明)。

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.7.0 #1 SMP Wed Jan 9 04:46:12 CST 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/issue
CentOS Linux release 6.0 (Final)
Kernel \r on an \m

[root@localhost ~]# rpm -q glibc
glibc-2.12-1.7.el6.x86_64
glibc-2.12-1.7.el6.i686
[root@localhost ~]# gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC)
[root@localhost ~]# make -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-unknown-linux-gnu
[root@localhost ~]# cd /home/work/
[root@localhost work]# mkdir glibc
[root@localhost work]# cd glibc/
[root@localhost glibc]# rz
rz waiting to receive.
[root@localhost glibc]# ls
glibc-2.15.tar.bz2

2,解压配置:

[root@lenky glibc]# tar -xjf glibc-2.15.tar.bz2
[root@lenky glibc]# cd glibc-2.15
[root@lenky glibc-2.15]# mkdir -p /usr/local/glibc-2.15
[root@lenky glibc-2.15]# ./configure --prefix=/usr/local/glibc-2.15/
checking build system type... i686-pc-linux-gnu
...
configure: error: you must configure in a separate build directory

出现上面的提示错误,在INSTALL文件内有说明,原因是不能在当前目录进行configure,所以:

[root@lenky glibc-2.15]# cd ..
[root@lenky glibc]# mkdir build/
[root@lenky glibc]# cd build/
[root@lenky build]# ../glibc-2.15/configure --prefix=/usr/local/glibc-2.15/
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
...
config.status: creating config.make
config.status: creating Makefile
config.status: creating config.h
config.status: executing default commands

3,编译:

[root@localhost build]# make
[root@localhost build]# make install
[root@localhost build]# ls /usr/local/glibc-2.15/
bin  etc  include  lib  libexec  sbin  share

一般来说,glibc的升级不会遇到太大的问题,但如果出现很多乱七八糟的错误,那么原因可能就是步子迈太大导致,比如系统本身的glibc只有2.5,却升级一个2.17的glibc,遇到这种情况,可能的建议就是选择一个既满足升级需求,又版本比较低点的新glibc进行升级。

编译一个使用新glibc的应用程序试试:

[root@localhost work]# cat env.c
/**
 * filename: env.c
 */
#include <stdio.h>

int main(int argc, char *argv[], char *envp[])
{
    printf("argc:%d, argv[0]:%s, envp[0]:%s\n", argc, argv[0], envp[0]);
    return 0;
}
[root@localhost work]# gcc -g -O0 env.c -o env -Wl,--rpath=/usr/local/glibc-2.15/ -Wl,--dynamic-linker=/usr/local/glibc-2.15/lib/ld-linux-x86-64.so.2
[root@localhost work]# ldd env
        linux-vdso.so.1 (0x00007fffde1ff000)
        libc.so.6 => /usr/local/glibc-2.15/lib/libc.so.6 (0x00007f28f9f26000)
        /usr/local/glibc-2.15/lib/ld-linux-x86-64.so.2 (0x00007f28fa2ce000)
[root@localhost work]# ./env
argc:1, argv[0]:./env, envp[0]:HOSTNAME=localhost.localdomain
[root@localhost work]#

参考:
http://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host/851229#851229

转载请保留地址:http://lenky.info/archives/2013/02/06/2205http://lenky.info/?p=2205


备注:如无特殊说明,文章内容均出自Lenky个人的真实理解而并非存心妄自揣测来故意愚人耳目。由于个人水平有限,虽力求内容正确无误,但仍然难免出错,请勿见怪,如果可以则请留言告之,并欢迎来讨论。另外值得说明的是,Lenky的部分文章以及部分内容参考借鉴了网络上各位网友的热心分享,特别是一些带有完全参考的文章,其后附带的链接内容也许更直接、更丰富,而我只是做了一下归纳&转述,在此也一并表示感谢。关于本站的所有技术文章,欢迎转载,但请遵从CC创作共享协议,而一些私人性质较强的心情随笔,建议不要转载。

法律:根据最新颁布的《信息网络传播权保护条例》,如果您认为本文章的任何内容侵犯了您的权利,请以或书面等方式告知,本站将及时删除相关内容或链接。

分类: *nix技术, 应用程序 标签: ,
  1. memon
    2013年2月17日14:13 | #1

    centos 如果自己升级内核 glibc这种基础库 碰上问题会很麻烦吧。。。

  1. 本文目前尚无任何 trackbacks 和 pingbacks.