06月19, 2019

RHEL 6编译安装glibc

configure不能在源码目录下,所以搞个build目录:

../configure --prefix=/opt/glibc CC=gcc CXX=g++

下面是装2.29的时候遇到的问题和解决办法。但是总感觉不太彻底。建议不要没事找事,只安装需要的版本的glibc即可。RHEL 6.5装glibc 2.17一点问题都没有。

毕竟系统各种库的版本太低,所以会遇到各种问题。

configure遇到:

configure: error: 
*** These critical programs are missing or too old: as GNU ld make bison compiler python
*** Check the INSTALL file for required versions.

先编译安装binutils

然后,编译安装GCC

编译安装GNU make,并创建gmake的软链接到make。

编译安装Python3

如果你有root权限,就不要自己编译安装了。

然后报错:

checking installed Linux kernel header files... missing or too old!
configure: error: GNU libc requires kernel header files from
Linux 3.2.0 or later to be installed before configuring.
The kernel header files are found usually in /usr/include/asm and
/usr/include/linux; make sure these directories use files from
Linux 3.2.0 or later.  This check uses <linux/version.h>, so
make sure that file was built correctly when installing the kernel header
files.  To use kernel headers not from /usr/include/linux, use the
configure option --with-headers.

下载Linux Kernel,xz需要先xz -d再解压tar。执行make headers_install -j,将头文件安装到当前目录下的usr/include目录中。

最后,再进行glibc的configure,记得需要用--with-headers=手动指定linux headers目录。

../configure --prefix=/opt/glibc CC=gcc CXX=g++ --with-headers=/opt/linux-5.1.12/usr/include

然后编译安装即可。


会遇到报错:

makedb.c:50:11: fatal error: selinux/selinux.h: No such file or directory
 # include <selinux/selinux.h>
           ^~~~~~~~~~~~~~~~~~~
compilation terminated.

selinux一般用不太到,所以我们直接在configure时加上--without-selinux即可。

可能在make install时还会遇到:

/opt/glibc/glibc-2.29/build/elf/sln /opt/glibc/glibc-2.29/build/elf/symlink.list
FATAL: kernel too old
make[1]: *** [Makefile:106: install-symbolic-link] Aborted (core dumped)
make[1]: Leaving directory '/opt/glibc/glibc-2.29'
make: *** [Makefile:12: install] Error 2

需要在configure时,根据系统内核版本,加上如--enable-kernel=2.6.32这样的参数。如果编译过,最好先make clean。但是我在make install时仍然会报错,感觉上是这个参数没起作用。

使用file查看sln这一程序,发现它需要3.2.0的内核,我的方法是手动编译它,直接gcc -o sln sln.o即可。但是仍有其他很多程序要用3.2.0的内核。


注意:在使用时,要保持ld.solibc.so的一致性。需要在程序编译时指定新的动态链接器ld.so,或者使用新的动态链接器执行以前编译的程序,并在LD_LIBRARY_PATH中加入libc.so的路径,或者在新的动态链接器执行时加入类似--library-path /opt/glibc/glibc/lib:$LD_LIBRARY_PATH的参数。例如:

/opt/glibc/glibc/lib/ld-2.17.so --library-path /opt/glibc/glibc/lib:$LD_LIBRARY_PATH /bin/ls

本文链接:https://debug.fanzheng.org/post/compile-and-install-glibc-in-RHEL6.html

-- EOF --

Comments

评论加载中...

注:如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理。