http://blog.csdn.net/clodfront/article/details/7046122

 

在redhat server 6 安装gcc-4.5.2

 

安装gcc 有几个依赖项 gmp mpgr mpc  ppl我现在装的是(gmp-4.3.2.tar.bz2  mpfr-2.4.2.tar.bz2 mpc-0.8.1.tar.gz  )

这三个也有以来关系 得先安装gmp 其次mpfr 再是 mpc 然后是ppl

gmp mpfr  可以到http://mirror.bjtu.edu.cn/gnu/ 下载

mpc   http://www.multiprecision.org/ 

 

 

先解压三个压缩包

#tar –jxvf  * .bz2

#tar –zxvf  *.gz

得到三个文件夹

gmp-4.3.2   mpfr-2.4.2  mpc-0.8.1

 

安装gmp

创建工作目录 然后进去

#mkdir gmp-build

#cd gmp-build

gmp的配置很简单

#../gmp-4.3.2/configure --prefix=/usr/gmp-4.3.2  --enable-cxx     (我将gmp安装在/usr/gmp-5.0.2  其他类似)

#make      …………………………编译

#make check …………………………检查  (不是必须的  不过走一下过场也好)

#make install …………………………安装

到这以后要修改修改环境变量  (我没有修改时 是失败了) 

#vi /etc/profile  

在/etc/profile 中添加一句

export LD_LIBRARY_PATH=/usr/gmp-4.3.2/lib:$LD_LIBRARY_PATH

#source /etc/profile      (这句好像可以不要 不清楚这是不是重新加载环境变量)

#cd ..  退出gmp工作目录

 

安装mpfr

创建工作目录 然后进去

#mkdir mpfr-build

#cd mpfr-build

mpfr的配置很简单

#../mpfr-2.4.2/configure --prefix=/usr/mpfr-2.4.2 --with-gmp=/usr/gmp-4.3.2     (mpfr 依赖gmp)

#make      …………………………编译

#make check …………………………检查  (不是必须的  不过走一下过场也好)

#make install …………………………安装

到这以后要修改修改环境变量

#vi /etc/profile  

在/etc/profile 修改刚才添加的那句

export LD_LIBRARY_PATH=/usr/gmp-4.3.2/lib:/usr/mpfr-2.4.2/lib:$LD_LIBRARY_PATH

#source /etc/profile      (这句好像可以不要 不清楚这是不是重新加载环境变量)

#cd ..         退出mpfr的工作目录

 

 

安装 mpc

创建工作目录 然后进去

#mkdir mpc-build

#cd mpc-build

mpc的配置很简单

#../mpc-0.8.1/configure --prefix=/usr/mpc-0.8.1 --with-gmp=/usr/gmp-4.3.2 --with-mpfr=/usr/mpfr-2.4.2     (mpc 依赖gmp 和 mpfr)

#make      …………………………编译

#make check …………………………检查  (不是必须的  不过走一下过场也好)

#make install …………………………安装

到这以后要修改修改环境变量

#vi /etc/profile  

在/etc/profile 修改刚才添加的那句

export LD_LIBRARY_PATH=/usr/gmp-4.3.2/lib:/usr/mpfr-2.4.2/lib:/usr/mpc-0.8.1/lib:$LD_LIBRARY_PATH

#source /etc/profile      (这句好像可以不要 不清楚这是不是重新加载环境变量)

 

 

到这里如果没问题的话就可以安装GCC  不过我的系统是出了问题  在安装的过程中报错了 提示找不到 zlib.h   以及 Z_OK  Z_NULL 等 没定义之类事

就得先安装zlib了    我在网上找了一个zlib-1.2.5.tar.gz

 将他解压了就差不多了

#tar –zxvf zlib-1.2.5.tar.gz

得到了三个文件夹    include  lib   share   很郁闷啊 居然没安装或者配置需要的文件 

没办法我 就直接将

  include里面的东西考到 /usr/include  里面

  lib里面的东西考到 /usr/lib  里面 

share   里面的东西考到 /usr/ share   里面 

 

 

其实一般的系统里面中都会有zlib的  不知为何我的没有

 

 

好了现在可以正式安装gcc了

 

我的gcc文件是gcc-4.5.2.tar.bz2  还和以前一样 过程差不多

 

#mkdir gcc-build

#cd gcc-build

# ../gcc-4.5.2/configure --prefix=/usr/gcc-4.5.2 --mandir=/usr/share/man --infodir=/usr/share/info --enable-bootstrap --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --enable-languages=c,c++ --with-gmp=/usr/gmp-4.3.2 --with-mpfr=/usr/mpfr-2.4.2 --with-mpc=/usr/mpc-0.8.1 --without-ppl --without-cloog

 

(以上即是gcc的简单配置了  我讲gcc安装在/usr/gcc-4.6.2  其详细说明可以查看gcc的相关书名文档)

#make &&make install     (这里编译和安装就一起搞了 因为是在太久了 我花了三四个小时   )

 

如果以上没问题的话 说明已经安装成功了  不过  还有接下来的配置 其实和上面的也差不多

#vi /etc/profile  

在/etc/profile 修改刚才添加的那句

export LD_LIBRARY_PATH=/usr/gmp-5.0.2/lib: /usr/mpfr-2.4.2/lib:/usr/mpc-0.8.1/lib: /usr/gcc-4.6.2/lib:$ LD_LIBRARY_PATH

export LD_RUN_PATH=/usr/gcc-4.6.2/lib:$LD_RUN_PATH

export PATH=/usr/gcc-4.5.2/bin:$PATH

/#source /etc/profile      (这句好像可以不要 不清楚这是不是重新加载环境变量)

如果需要的话就重启一下吧  不过我的也真的要重启 不重启的话 好多命令都用不了了  就连  #source /etc/profile  都用不了

 

报错

/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: 没有那个文件或目录compilation terminated.make[5]: *** [_muldi3.o] 错误 1make[5]: Leaving directory `/home/QA/gcc-build/x86_64-unknown-linux-gnu/32/libgcc'make[4]: *** [multi-do] 错误 1make[4]: Leaving directory `/home/QA/gcc-build/x86_64-unknown-linux-gnu/libgcc'make[3]: *** [all-multi] 错误 2make[3]: Leaving directory `/home/QA/gcc-build/x86_64-unknown-linux-gnu/libgcc'make[2]: *** [all-stage1-target-libgcc] 错误 2make[2]: Leaving directory `/home/QA/gcc-build'make[1]: *** [stage1-bubble] 错误 2make[1]: Leaving directory `/home/QA/gcc-build'make: *** [all] 错误 2

 

rpm -qa |grep glibc-devel

[MPP@MPP-M ~]$ rpm -qa|grep glibc-devel
glibc-devel-2.12-1.80.el6.x86_64


{glibc-devel-2.12-1.80.el6.i686}

安装glibc-devel-2.12-1.80.el6.i686.rpm

 

错误排除后,安装gcc***成功后,gcc -v提示

[QA@QA-Test01 usr]$ gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/gcc-4.5.2/libexec/gcc/x86_64-unknown-linux-gnu/4.5.2/lto-wrapper
目标:x86_64-unknown-linux-gnu
配置为:../gcc-4.5.2/configure --prefix=/usr/gcc-4.5.2 --mandir=/usr/share/man --infodir=/usr/share/info --enable-bootstrap --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --enable-languages=c,c++ --with-gmp=/usr/gmp-5.0.2 --with-mpfr=/usr/mpfr-2.4.2 --with-mpc=/usr/mpc-0.8.1 --without-ppl --without-cloog
线程模型:posix
gcc 版本 4.5.2 (GCC)

但是编译boost时候看到仍然用到的是以前的gcc版本

这时候就要把以前的gcc给移除重新创建新的连接就可以了

sudo mv /usr/bin/gcc /usr/bin/gcc_bak

sudo ln -s /usr/bin/gcc /usr/gcc-4.5.2/bin/gcc

ok了