解决CentOS 6 i386编译 glibc 遇到的错误

本文共371字。
Copyright: 知识共享署名 非商业性使用 相同方式共享 4.0 国际许可协议 | CC BY-NC-SA 4.0

由于 CentOS6 系统默认的 glibc 版本较低,在尝试编译升级时遇到了 Error: invalid identifier for “.ifdef”,在此记录解决方案。

编译安装

官网下载:ftp://ftp.gnu.org/gnu/glibc/

下载并编译安装

1
2
3
4
5
6
7
8
9
wget http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.gz
wget http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz
tar -zxf glibc-2.15.tar.gz
tar -zxf glibc-ports-2.15.tar.gz
mv glibc-ports-2.15 glibc-2.15/ports
mkdir glibc-build-2.15
cd glibc-build-2.15
../glibc-2.15/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
make all && make install

解决错误

sysdeps/i386/fpu/s_frexp.S:66: Error: invalid identifier for “.ifdef”

1. 修改文件 pt-initfini.c

在 glibc 源码目录下找到文件 nptl/sysdeps/pthread/pt-initfini.c,约在 46 行左右:asm ("\n#include \"defs.h\"");

在其后增加代码:

1
2
3
4
asm ("\n#if defined __i686 && defined __ASSEMBLER__");
asm ("\n#undef __i686");
asm ("\n#define __i686 __i686");
asm ("\n#endif");

2. 修改文件 sysdep.h

在 glibc 源码目录下找到文件 sysdeps/unix/sysv/linux/i386/sysdep.h ,约在 30 行左右:#include <tls.h>

在其后增加代码:

1
2
3
4
#if defined __i686 && defined __ASSEMBLER__
#undef __i686
#define __i686 __i686
#endif

3. 重新编译

1
make -j $(nproc) && make install

判断当前 GLIBC 版本

1
ldd --version

如下则成功安装

1
2
3
4
5
ldd (GNU libc) 2.15
Copyright (C) 2012 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.
Written by Roland McGrath and Ulrich Drepper.

参考链接:http://blog.sina.com.cn/s/blog_602f877001010tpt.htmlttp://blog.sina.com.cn/s/blog_602f877001010tpt.html