Premise: Ensure the old version of the gcc,g++ exist! Root user
1. Download source code and dependency package source code: New Directory Bak
wget http://ftp.gnu.org/gnu/gcc/gcc-4.9.3/gcc-4.9.3.tar.gz
#Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+
wget http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz
wget http://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.gz
wget http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.0.tar.gz
$ ls bak/*.gz
bak/gcc-4.9.3.tar.gz bak/gmp-5.0.1.tar.gz bak/mpc-0.9.tar.gz bak/mpfr-3.1.0.tar.gz
2. Compiling
Unzip the tar package, and create a new compilation directory T T1 T2 T3, respectively, to compile the above source code
$ ls Bak
t T1 T2 T3
CD T1 ./gmp-5.0.1/configure--prefix=/usr/local/gmp-5.0.1 Make Make InstallCD T2 ./mpfr-3.1.0/configure--prefix=/usr/local/mpfr-3.1.0--with-gmp=/usr/local/gmp-5.0.1 Make Make InstallCD t3 ./mpc-0.9/configure--prefix=/usr/local/mpc-0.9--with-gmp=/usr/local/gmp-5.0.1--with-mpfr=/usr/local/mpfr-3.1.0 Make Make Install#设置链接, in/etc/profile file at the end of the Add, note the modified after running #source/etc/Profile makes it effective to export Ld_library_path= $LD _library_path:/usr/local/mpc-0.9/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-3.1.0/LIBCD T../GCC-4.9.3/configure--prefix=/usr/local/GCC-4.9.3--with-mpc=/usr/local/mpc-0.9--with-gmp=/usr/local/gmp-5.0.1--with-mpfr=/usr/local/mpfr-3.1.0--disable-multilib--enable-languages=c,c++--enable-threads=posix--disable-checking Make Make Install
Compiling the installation
3. Switch GCC to the new version:
[Email protected] bin]# pwd
/usr/bin
[Email protected] bin]# mv GCC gcc-4.4.7
[Email protected] bin]# ln-s/USR/LOCAL/GCC-4.9.3/BIN/GCC/USR/BIN/GCC
[Email protected] bin]# MV g++ g++-4.4.7
[Email protected] bin]# ln-s/usr/local/gcc-4.9.3/bin/g++/usr/bin/g++
4. OK, confirm version
Gcc-v
g++-V
----Supplement:
If you can network, there are the following two reference, not tested
1. Download dependencies for compilation requirements
Reference [1] says: This magical script file will help us to download, configure, install dependent libraries, can save us a lot of time and effort.
CD gcc-4.9.3
./contrib/download_prerequisites
2. Compiling (note: This step is time consuming)
Make-j4
The-J4 option is the make to multi-core processor optimization, if not successful use makes, the relevant optimization options can be moved to the reference [2].
If error is focused on X86_64UNKNOWN-LINUX-GNU/32/LIBGCC and X86_64-UNKNOWN-LINUX-GNU/LIBGCC
According to reference [3], install the following two packages (for centos6.x only):
Yum-y Install glibc-devel.i686 Glibc-devel
RHEL 6.5 Upgrade GCC 4.9.3