Ubuntu 安裝與更新 GCC

轉自 http://lwzhanghz.blog.163.com/blog/static/1368263692012516919455/

2012-06-16 10:23:37|  分類: Ubuntu|字號 訂閱

一、首先從GNU上下載GCC包,ftp://gcc.gnu.org/,我使用的是最新發布版本gcc-4.7.0.tat.gz,

1)  tar zxvf gcc-4.7.0.tar.gz

2)  cd gcc-4.7.0

3) ./congigure

此時會出現這樣的錯誤:
                        gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+
        從錯誤中可以看出:GCC編譯需要GMP, MPFR, MPC這三個庫,我使用的版本爲gmp-5.0.5,mpfr-3.1.0和mpc-0.8.1。這三個包從下面的地址下載:
http://gmplib.org/,http://www.mpfr.org/,http://www.multiprecision.org/
  
 二、安裝GMP時也出現了錯誤:
                              No usable m4 in $PATH or /usr/5bin (see config.log for reasons).
        由此可以看出是缺少M4文件。可以去這裏下載:http://ftp.gnu.org/gnu/m4/  。我這裏下載了m4-1.4.15.tar.gz   
1)  tar zxvf m4-1.4.15.tar.gz
2)  cd m4-1.4.15
3)  ./configure
4)  make
5)  make check(強烈建議檢查,確保正確)
6)  make install(需要root,建議在root中安裝)


三、有了M4就可以裝別的了。由於MPFR和MPC都依賴於GMP包,所以首先安裝GMP。
1)tar jxvf gmp-5.0.5.tar.bz2
2)cd gmp-5.0.5
3)./configure
4)make
5)make check 
6)  make install

 

四、安裝MPFR
1)  tar jxvf mpfr-3.1.0.tar.bz2
2)  cd mpfr-3.1.0
3)  ./configure
4)  make

出現問題:

/usr/lib/gcc/i486-linux-gnu/4.4.1/cc1:  error while loading shared libraries: libgmp.so.10:cannot open shared  object file: No such file or directory.

解決辦法:

重啓cache,在Synaptic Package administrator中安裝squid,然後運行:

$ /usr/sbin/squid -z

重新運行:

$ ./configure

$ make

運行成功!

5)  make check
6)  sudo make install


五、安裝MPC

1)  tar zxvf mpc-0.8.1.tar.gz
2)  cd mpc-0.8.1
3)  ./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib
4)  make
5) ldconfig -v(出現:error while loading shared libraries: libmpfr.so.1: cannot open shared objec,可以自己去man ldd 和ldconfig) 
6) make check
7)  make install


六、這幾個庫的默認位置是/usr/local/include和/usr/local/lib,GCC編譯時可能會找不到這三個庫,需要確認庫位置是否在環境變量LD_LIBRARY_PATH中,查看環境變量內容可以用命令
                $echo $LD_LIBRARY_PATH
        設置該環境變量命令如下:
                $export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
        現在開始安裝GCC
1) tar xvf gcc-4.5.1.tar.gz
2) cd gcc-4.5.1
3) ./configure
4) make

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章