解决编译glibc遇到的错误 Error: invalid identifier for ".ifdef"

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

编译安装

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

下载并编译安装

wget http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.gzwget http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gztar -zxf glibc-2.15.tar.gztar -zxf glibc-ports-2.15.tar.gzmv glibc-ports-2.15 glibc-2.15/portsmkdir glibc-build-2.15cd glibc-build-2.15../glibc-2.15/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/binmake 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\"");

在其后增加代码:

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>

在其后增加代码:

#if defined __i686 && defined __ASSEMBLER__#undef __i686#define __i686 __i686#endif

3.重新编译

make all && make install

判断当前GLIBC版本

ldd --version

如下则成功安装

ldd (GNU libc) 2.15Copyright (C) 2012 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Written by Roland McGrath and Ulrich Drepper.
(0)

相关推荐