UBuntu11.04 server编译安装GCC4.6.1

安装需要的一些库

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

编译依赖库

gmp

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

mpfr

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

mpc

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

编译GCC

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

旧版本的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


你可能感兴趣的:(ubuntu)