Saturday 15 June 2013

Compile GCC 4.6.3

Let’s compiling your gcc, it’s so fun. Following is the very basic  instructions for newbie. If you want to compile with more option, you can go to homepage gcc.gnu.org/install/ for details.
Go to and find which pakage needed ftp.gnu.org/gnu
1. build & install gmp:
tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/
./configure --prefix=/usr/local/gmp
make && make install
cd ..
2. build & install mpfr:
tar jxf mpfr-2.4.2.tar.bz2 ;cd mpfr-2.4.2/
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
make && make install
cd ..
3. build & install mpc:
tar xzf mpc-0.8.1.tar.gz ;cd mpc-0.8.1
./configure --prefix=/usr/local/mpc --with-mpfr=/usr/local/mpfr --with-gmp=/usr/local/gmp
make && make install
cd ..
4. build & install gcc4.6.3
tar jxf gcc-4.6.3.tar.bz2 ;cd gcc-4.6.3
./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp -w-ith-mpfr=/usr/local/mpfr/ --with-mpc=/usr/local/mpc/
if [ $? -eq 0 ];then
echo "this gcc configure is success"
else
echo "this gcc configure is failed"
fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
make && make install
[ $? -eq 0 ] && echo install success
5. set up the gcc env:
--> this is really important.
cp gcc.4.6.3.conf /etc/ld.so.conf.d/gcc.4.6.3.conf
ldconfig
mv /usr/bin/gcc /usr/bin/gcc_old
mv /usr/bin/g++ /usr/bin/g++_old
mv /usr/bin/c++ /usr/bin/c++_old
ln -s -f /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -s -f /usr/local/gcc/bin/g++ /usr/bin/g++
ln -s -f /usr/local/gcc/bin/c++ /usr/bin/c++
cp /usr/local/gcc/lib64/libstdc++.so.6.0.16 /usr/lib64/.
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s -f /usr/lib64/libstdc++.so.6.0.16 /usr/lib64/libstdc++.so.6
6. finished.
you could run gcc --version to check if the current gcc version is gcc4.6.3, and also need to check g++, to see if the version is changed to g++4.6.3 too.