---
title: "笔记：使用源码升级至glibc-2.7"
author: "OpenNaive"
date: "2011-11-01T15:45:28Z"
tags: ["glibc"]
categories: ["操作系统"]
slug: "glibc-2-7"
draft: false
lastmod: "2011-11-05T10:49:30Z"
id: 1226790
url: "https://opennaive.iteye.com/blog/1226790"
---

用的redhat版本太老，而安装mentohust，需要glibc-2.7版本以上，所以从[GNU的官网](http://ftp.gnu.org/gnu/libc/) 上下载了glibc-2.7的源码，将原有的glibc-2.5升级到2.7。必须注意的是，几乎所有的应用程序都依赖于glibc的动态库，重新编译安装glibc必须非常谨慎，一旦出错可能导致系统无法继续使用。所以强烈建议阅读源码目录下的INSTALL和FAQ文档。

## 1 ../glibc-2.7/configure

第一步是配置glibc，出于安全的考虑，glibc不允许在源码目录树下编译，必须新建一个目录，然后在新建目录下运行configure，我就在源码目录的父目录下建了一个glibc-build目录，这样一旦出错就将整个目录移除即可。

 

congfiure最常用的选项是--prefix，--prefix指定了glibc安装的位置，默认是安装到/usr/lcoal，glibc会强烈建议不要安装到这个目录下，通常的做法是--prefix=/usr，这会将glibc安装为linux系统的标准库。

\*\** On GNU/Linux systems the GNU C Library should not be installed into  
\*\** /usr/local since this might make your system totally unusable.  
\*\** We strongly advise to use a different prefix.  For details read the FAQ.  
\*\** If you really mean to do this, run configure again using the extra  
\*\** parameter \`--disable-sanity-checks'.

 

## 2 make

第二步是编译glibc，make会打印很多信息，而那些包含“\*\*\*”的信息意味着非常严重的错误。glibc的编译相当耗时，可以给make加上-j选项并行编译glibc。我在make的时候遇到了以下问题。

make 写道

/root/source/glibc-build/libc\_pic.os: In function \`\_\_libc\_fork':  
/root/source/glibc-2.7/posix/../nptl/sysdeps/unix/sysv/linux/i386/../fork.c:76: undefined reference to \`\_\_sync\_bool\_compare\_and\_swap\_4'  
/root/source/glibc-build/libc\_pic.os: In function \`\_\_nscd\_drop\_map\_ref':  
/root/source/glibc-2.7/nscd/nscd-client.h:320: undefined reference to \`\_\_sync\_fetch\_and\_add\_4'  
/root/source/glibc-build/libc\_pic.os: In function \`nscd\_getpw\_r':  
/root/source/glibc-2.7/nscd/nscd\_getpw\_r.c:232: undefined reference to \`\_\_sync\_fetch\_and\_add\_4'  
/root/source/glibc-build/libc\_pic.os: In function \`\_\_nscd\_drop\_map\_ref':  
/root/source/glibc-2.7/nscd/nscd-client.h:320: undefined reference to \`\_\_sync\_fetch\_and\_add\_4'  
/root/source/glibc-build/libc\_pic.os: In function \`nscd\_getgr\_r':  
/root/source/glibc-2.7/nscd/nscd\_getgr\_r.c:321: undefined reference to \`\_\_sync\_fetch\_and\_add\_4'  
/root/source/glibc-build/libc\_pic.os: In function \`\_\_nscd\_drop\_map\_ref':  
/root/source/glibc-2.7/nscd/nscd-client.h:320: undefined reference to \`\_\_sync\_fetch\_and\_add\_4'  
/root/source/glibc-build/libc\_pic.os:/root/source/glibc-2.7/nscd/nscd\_gethst\_r.c:400: more undefined references to \`\_\_sync\_fetch\_and\_add\_4' follow  
/root/source/glibc-build/libc\_pic.os: In function \`\_\_nscd\_get\_map\_ref':  
/root/source/glibc-2.7/nscd/nscd\_helper.c:404: undefined reference to \`\_\_sync\_val\_compare\_and\_swap\_4'  
/root/source/glibc-build/libc\_pic.os: In function \`\*\_\_GI\_\_\_libc\_freeres':  
/root/source/glibc-2.7/malloc/set-freeres.c:39: undefined reference to \`\_\_sync\_bool\_compare\_and\_swap\_4'  
collect2: ld returned 1 exit status  
make\[1]: \*\** \[/root/source/glibc-build/libc.so] Error 1  
make\[1]: Leaving directory \`/root/source/glibc-2.7'  
make: \*\** \[all] Error 2

 

碰到这个问题需要为为CFLAGS添加march选项。

```
echo "CFLAGS += -march=i486" > configparms
```

执行make命令时会将configparms里的内容按照MakeFile的规则进行解析。

## 3 make check

在安装之前，先用make check检查是否存在错误，一定不要使用存在错误的库。这个check的过程实在太长，出现错误非常郁闷。我在check的时候遇到的问题是：

Timed out: the child process got signal Unknown signal 88

这个问题一直不知如何解决，多运行几次check之后错误又不见了。

## 4 make install

如果和我一样是从glibc-2.5升级到2.7，需要新建一个/usr/include目录，其中只能包含linux的头文件。

……install遇到各种问题，最后机器直接不能使用，神啊！

glibc太旧，不如换个新操作系统吧，亲！