天天看点

RedHat5.4升级安装GCC-4.8.3

安装的redhat版本

[[email protected] ~]$ lsb_release -a

LSB Version:    :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch

Distributor ID: RedHatEnterpriseServer

Description:    Red Hat Enterprise Linux Server release 5.4 (Tikanga)

Release:        5.4

Codename:       Tikanga

1.下载gcc-4.6.1安装包

gcc各版本浏览地址:http://ftp.gnu.org/gnu/gcc/

2.将gcc-4.6.1.tar.bz2放到/opt文件夹下解压

[[email protected] ~]# cd /opt

[[email protected] opt]# tar -xjvf gcc-4.8.3.tar.bz2

3.创建安装目录

[[email protected] opt]# mkdir /usr/local/gcc-4.8.3/

4.进入安装目录

[[email protected] opt]# cd /usr/local/gcc-4.8.3/

5.配置安装文件

[[email protected] gcc-4.8.3]# /opt/gcc-4.8.3/configure --prefix=/usr/local/gcc-4.8.3

(执行源目录 /opt/gcc-4.8.3/中的configure命令,配置将gcc安装到目标目录/usr/local/gcc-4.8.3/下,这里–prefix选项代表要将该库安装在哪里,我是装在/usr/local/gcc-4.8.3目录下,后面的安装都会用到这个选项)

如果执行这步的时候出现了如下错误:

----------------------------------------------------------------------------------

configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.

Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify

their locations.

----------------------------------------------------------------------------------

错误说明要安装gcc需要GMP、MPFR、MPC这三个库,可从ftp://gcc.gnu.org/pub/gcc/infrastructure/下载相应的压缩包。由于MPFR依赖GMP,而MPC依赖GMP和MPFR,所以要先安装GMP,其次MPFR,最后才是MPC。这里三个库我用的版本分别是gmp4.3.2,mpfr2.4.2和mpc0.8.1,都放在 /opt文件夹下。

①.安装gmp4.3.2

[ [email protected] opt]# tar jxvf gmp-4.3.2.tar.bz2

[ [email protected] opt]# mkdir /usr/local/gmp-4.3.2

[ [email protected] opt]# cd /usr/local/gmp-4.3.2

[ [email protected] gmp-4.3.2]# /opt/gmp-4.3.2/configure --prefix=/usr/local/gmp-4.3.2

[ [email protected] gmp-4.3.2]# make (编译)

[ [email protected] gmp-4.3.2]# make install (执行安装)

②安装mpfr2.4.2

[ [email protected] opt]# tar jxvf mpfr2.4.2.tar.bz2

[ [email protected] opt]# mkdir /usr/local/mpfr-2.4.2

[ [email protected] opt]# cd /usr/local/mpfr-2.4.2

[ [email protected] mpfr-2.4.2]# /opt/mpfr-2.4.2/configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2

(注意配置的时候要把依赖关系选项加进去)

[ [email protected] mpfr-2.4.2]# make

[ [email protected] mpfr-2.4.2]# make install

③安装mpc0.8.1

[ [email protected] opt]# tar jxvf gmpc0.8.1.tar.bz2

[ [email protected] opt]# mkdir /usr/local/mpc-0.8.1

[ [email protected] opt]# cd /usr/local/mpc-0.8.1

[ [email protected] mpc-0.8.1]# /opt/mpc-0.8.1/configure --prefix=/usr/local/mpc-0.8.1 --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2

[ [email protected] mpc-0.8.1]# make

[ [email protected] mpc-0.8.1]# make install

④再次安装GCC 配置安装选项

[ [email protected] mpc-0.8.1]# cd /usr/local/gcc- 4.8.3

[ [email protected] gcc- 4.8.3]# /opt/gcc- 4.8.3/configure --prefix=/usr/local/gcc- 4.8.3 -enable-threads=posix -disable-checking -disable-multilib -enable-languages=c,c++ --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1

6.编译安装文件

[ [email protected] gcc-4.8.3]# make

大概需要1个小时左右

第二个错误出现了:

打开/usr/local/gcc-4.8.3/i686-pc-linux-gnu/libgcc/config.log

ctrl+f查找error 发现如下错误

/----------------------------------------------------------------------------------

/usr/local/gcc-4.8.3/./gcc/cc1: error while loading shared libraries: libmpc.so.2: cannot open shared object file: No such file or directory

configure:3058: $? = 1

----------------------------------------------------------------------------------/

在网上找到了解决方法,需要添加环境变量LD_LIBRARY_PATH以指出前面三个库的位置,键入以下命令:

[[email protected] gcc-4.8.3]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib

再次执行步骤6→

大概三小时后···

终于编译成功了,效果图入下:

RedHat5.4升级安装GCC-4.8.3

7.执行安装gcc

[[email protected] gcc-4.8.3]# make install

[[email protected] gcc-4.8.3]# 

如果不出意外,那么到现在应该安装成功了,不过还是不能使用新版本的gcc,因为新版本的gcc还没有加入命令搜索路径中!

8.建立软链接

[[email protected] /]# sudo ln -s /usr/local/gcc-4.8.3/bin/gcc gcc48

[[email protected] /]# sudo ln -s /usr/local/gcc-4.8.3/bin/g++ g++48

9.添加环境变量 

[root@localhost linfeng]# export PATH=$PATH:/usr/local/gcc-4.8.3/bin/

继续阅读