sudo apt-get install build-essential
sudo apt-get install zlibc
sudo apt-get install zlib1g-dev
sudo apt-get install m4
sudo apt-get install gcc-multilib
进入/usr/src目录
wgethttp://gcc.igor.onlinedirect.bg/releases/gcc-4.6.1/gcc-4.6.1.tar.bz2
tar jxvf gcc-4.6.1.tar.bz2
wgetftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
tar jxvf gmp-4.3.2.tar.bz2
mkdir gmp_build
cd gmp_build
../gmp-4.3.2/configure —prefix=/usr/gmp-4.3.2
make
make check
make install
wgetftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
tar jxvf mpfr-2.4.2.tar.bz2
mkdir mpfr_build
cd mpfr_build
../mpfr-2.4.2/configure —prefix=/usr/mpfr-2.4.2 —with-gmp=/usr/gmp-4.3.2
make
make check
make install
wgetftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
tar zxvf mpc-0.8.1.tar.gz
mkdir mpc_build
cd mpc_build
../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
make
make check
make install
mkdir gcc_build
cd gcc_build
../gcc-4.6.1/configure —prefix=/usr/gcc-4.6.1 —enable-threads=posix —disable-checking —disable-multilib —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
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/mpc-0.8.1/lib:/usr/gmp-4.3.2/lib:/usr/mpfr-2.4.2/lib
make
apt-get install dejagnu
apt-get install autogen
make check
make install
If compile error,can't find error.h in some files,use the following command:
sudo ln -sv /usr/src/linux-headers-2.6.38-10/arch/x86/include/asm /usr/include/asm
旧版本的gcc在/usr/bin目录
cd /usr/bin
mv gcc gcc_bk
mv g++ g++_bk
mv cpp cpp_bk
mv c++ c++_bk
Use the newest version
ln -s /usr/gcc-4.6.1/bin/gcc /usr/bin/gcc
ln -s /usr/gcc-4.6.1/bin/g++ /usr/bin/g++
ln -s /usr/gcc-4.6.1/bin/cpp /usr/bin/cpp
ln -s /usr/gcc-4.6.1/bin/c++ /usr/bin/c++
Add following into /etc/profile file
LD_LIBRARY_PATH=/usr/mpc-0.8.1/lib:/usr/gmp-4.3.2/lib:/usr/mpfr-2.4.2/lib:/usr/gcc-4.6.1/lib:/usr/lib
export LD_LIBRARY_PATH