Redhat EL4 install gcc 4.2

运行文件提示:
/usr/local/tools/fetion: /lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/local/tools/fetion/lib/libstdc++.so.6)
查看/lib/libgcc_s.so.1文件存在,是一个链接
[root@localhost tools]# ll /lib/libgcc_s.so.1
lrwxrwxrwx 1 root root 28 3月 14 08:16 /lib/libgcc_s.so.1 -> libgcc_s-3.4.3-20041213.so.1
查看系统的gcc版本是 gcc (GCC) 3.4.3
[root@localhost ~]# gcc --version
gcc (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
于是想升级GCC,没有找到GCC_4.2.0的rpm包,直接下载源码包了

一、升级前信息
[root@localhost ~]# gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
[root@localhost ~]# gcc --version
gcc (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
Copyright (C) 2004 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.
二、升级过程
[root@localhost ~]#wget http://ftp.gnu.org/pub/pub/gnu/gcc/gcc-4.2.0/gcc-4.2.0.tar.bz2
[root@localhost ~]# tar jxf gcc-4.2.0.tar.bz2
[root@localhost ~]# mkdir /usr/gcc4
[root@localhost ~]# cd /gcc-4.2.0
[root@localhost gcc-4.2.0]#./configure--prefix=/usr/gcc4
[root@localhost gcc-4.2.0]# make clean
[root@localhost gcc-4.2.0]# make
漫长啊,经过几个小时编译(资料说所有的组件几乎都要编译一遍)进行下一步
[root@localhost gcc-4.2.0]# make check
这里是不是测试吗?漫长的编译中在看鸟哥的教程学习的,怎么提示有错误了,不管了
make[1]: Entering directory `/root/gcc-4.2.0'
make[2]: Entering directory `/root/gcc-4.2.0/host-i686-pc-linux-gnu/fixincludes'
autogen -T http://www.cnblogs.com/./fixincludes/check.tpl http://www.cnblogs.com/./fixincludes/inclhack.def
make[2]: autogen:命令未找到
make[2]: *** [check] 错误 127
make[2]: Leaving directory `/root/gcc-4.2.0/host-i686-pc-linux-gnu/fixincludes'
make[1]: *** [check-fixincludes] 错误 2
make[1]: Leaving directory `/root/gcc-4.2.0'
make: *** [do-check] 错误 2
[root@localhost gcc-4.2.0]# make install
........
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/gcc4/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

查看版本还是旧版本信息,回头细想,才发现上面的是安装GCC而不是升级操作,后面把把新安装的库链接指向,删除旧库链接指看下。
....
旧版是用源码安装的,which gcc或者whereis gcc查看所在路径
[root@localhost bin]# which gcc
/usr/bin/gcc
[root@localhost bin]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
分别用新安装的/usr/gcc4/lib/下的gcc、g++、gcj指向替换相应旧的文件夹/usr/lib文件
[root@localhost ~]# cd /usr/lib
[root@localhost bin]# mv gcc gcc_bak
[root@localhost bin]# mv g++ g++_bak
[root@localhost bin]# mv gcj gcj_bak
[root@localhost bin]# ln -sv /usr/gcc4/bin/gcc gcc
[root@localhost bin]# ln -sv /usr/gcc4/bin/g++ g++
[root@localhost bin]# ln -sv /usr/gcc4/bin/gcj gcj
ldconfig -v重新加载库?先用后面再理解了
[root@localhost bin]# ldconfig -v
[root@localhost bin]# gcc -v
使用内建 specs。
目标:i686-pc-linux-gnu
配置为:./configure --prefix=/usr/gcc4
线程模型:posix
gcc 版本 4.2.0
OK,gcc 版本更新了,回头运行程序看下
/usr/local/tools/fetion: /lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/local/tools/fetion/lib/libstdc++.so.6)
xxd,折腾这么久还是给个原始错误
[root@localhost ~]# find / -name libgcc*
/lib/libgcc_s-3.4.3-20041213.so.1(链接的文件)
/lib/libgcc_s.so.1 (提示的文件)
......
/usr/gcc4/lib/libgcc_s.so.1 (新安装目录下的文件)
gcc4相同结构目录下也有这个libgcc_s.so.1文件,替换试下
[root@localhost ~]# mv /lib/libgcc_s.so.1 /lib/libgcc_s.so.1_bak
[root@localhost ~]# ln -s /usr/gcc4/lib/libgcc_s.so.1 /lib/libgcc_s.so.1
再运行程序就可以了

三、后记
1、gcc4应该安装在/usr/local/gcc4目录下的
2、有朋友建议 Red Hat用rpm -ivh gcc-4.1.2-33.i386.rpm这种方式安装会好一点
3、在centos4上相同的问题我直接用yum update gcc这条命令也可以把问题解决

四、相关链接
CentOS4安装飞信机器人笔记
http://hi.baidu.com/addcn/blog/item/8fc75461ef47ced78cb10d8b.html
LINUX安装GCC出现的问题
http://zhidao.baidu.com/question/51816308.html
gcc升级
http://coolangelan.blog.163.com/blog/static/104161247200904502222/
Linux操作系统下安装gcc4.2.*的方法
http://coolangelan.blog.163.com/blog/static/10416124720090453314726/
网友升级gentoo 到 gcc 4.2.0 笔记
-有个回复问值不值得我们这些菜鸟冒着生命危险去尝试
http://markmail.org/message/lyzrlvmwc53tdob7
Gentoo GCC升级指南
-emerge -uav gcc什么的,对着命令敲了几个提示错误没有看下去
http://www.gentoo.org/doc/zh_cn/gcc-upgrading.xml

原文地址:https://www.cnblogs.com/huqingyu/p/1619313.html