服務(wù)項目:網(wǎng)站建設(shè)、仿站、程序開發(fā)、APP開發(fā)設(shè)計、移動網(wǎng)站開發(fā)設(shè)計、企業(yè)網(wǎng)站設(shè)計、電子商務(wù)網(wǎng)站開發(fā)、網(wǎng)站維護、網(wǎng)站推廣、UX/UI 、HTML5、CSS3、JS / Jquery ...
四川浚??萍加邢薰?></a></div>
                    <div   id=四川???萍加邢薰? title=
四川浚??萍加邢薰?(開發(fā)設(shè)計官網(wǎng))TEL : 15308000360 / QQ : 38585404

您的位置:首頁 > 技術(shù)經(jīng)驗 > 服務(wù)器 > 正文

linux CentOS6.8編譯安裝GCC-6.3.0 升級GCC
技術(shù)支持服務(wù)電話:15308000360 【7x24提供運維服務(wù),解決各類系統(tǒng)/軟硬件疑難技術(shù)問題】

記錄編譯GCC 6.3.0時遇到的問題和解決方法,以備日后查詢...

若此篇文章還不能解決您的問題,請聯(lián)系QQ:38585404  (有償技術(shù)支持)
 
平時使用的服務(wù)器是CentOS6,自帶的gcc編譯器還是多年前發(fā)布的版本,很多新版本的軟件都不支持,因為不想升級操作系統(tǒng),只好自己下載源碼編譯。
 
安裝過程挺無語的,重復(fù)了很多次,只好記錄下來...
 
安裝依賴庫
 
GCC依賴于gmp 4.2+, mpfr 2.4+和mpc 0.8+,這里直接下載安裝最新的版本。
 
安裝gmp 6.1.2
wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz
tar xvf gmp-6.1.2.tar.xz cd gmp-6.1.2
./configure --prefix=/usr/local/gmp

make && make install
安裝mpfr 3.1.5 mpfr依賴于gmp
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.gz
tar xvf mpfr-3.1.5.tar.gz
cd mpfr-3.1.5
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp

make && make install
安裝mpc 1.0.3 mpc依賴于gmp和mpfr
wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
tar xvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp -with-mpfr=/usr/local/mpfr

make && make install
安裝GCC 6.3.0
wget ftp://ftp.gnu.org/gnu/gcc/gcc-6.3.0/gcc-6.3.0.tar.gz
tar xvf gcc-6.3.0.tar.gz
cd gcc-6.3.0
./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc

make -j8
make install
安裝過程中可能會出現(xiàn):
“checking for suffix of object files... configure: error: cannot compute suffix of object files: cannot compile

See `config.log' for more details.

make[2]: *** [configure-stage1-target-libgcc] Error 1

make[2]: Leaving directory `/tmp/gcc-6.3.0'

make[1]: *** [stage1-bubble] Error 2

make[1]: Leaving directory `/tmp/gcc-6.3.0'

make: *** [bootstrap] Error 2
解決方法:
yum install libgcc.i686
頭一次我也看到這個,執(zhí)行后去編譯還是出錯,在網(wǎng)上找到這個方法,雖然安裝后沒什么用,但是還是安裝上吧。

實際解決辦法:編輯變量,把我們安裝的gmp,mpfr,mpc加進去
vi /etc/ld.so.conf
添加部分:
/usr/local/lib        #這個是默認系統(tǒng)的變量
/usr/local/gmp/lib
/usr/local/mpfr/lib
/usr/local/mpc/lib
/usr/local/mysql/lib  #我服務(wù)器上安裝了MySQL 所以這里是MySQL的變量
/usr/local/openssl/lib #openssl變量
添加保存后記得更新動態(tài)庫的緩存:
ldconfig -v
更新后再去重新編譯安裝。

相信到這里你才真正成功編譯安裝完成 

備份系統(tǒng)默認的gcc版本
mv /usr/bin/gcc /usr/bin/gcc-bak
mv /usr/bin/g++ /usr/bin/g++-bak
mv /usr/bin/c++ /usr/bin/c++-bak
創(chuàng)建新的gcc軟連接
ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc/bin/c++ /usr/bin/c++
ln -s /usr/local/gcc/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc/lib64/libstdc++.so.6.0.22 /usr/lib64/libstdc++.so.6
查看gcc版本:
gcc --version

還有一種方法(直接替換現(xiàn)有版本):
安裝gmp 6.1.2
wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz
tar xvf gmp-6.1.2.tar.xz cd gmp-6.1.2
./configure

make && make install
安裝mpfr 3.1.5 mpfr依賴于gmp
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.gz
tar xvf mpfr-3.1.5.tar.gz
cd mpfr-3.1.5
./configure --with-gmp-include=/usr/local/include \
    --with-gmp-lib=/usr/local/lib

make && make install
安裝mpc 1.0.3 mpc依賴于gmp和mpfr
wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
tar xvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure --with-mpfr-include=/usr/local/include \
    --with-mpfr-lib=/usr/local/lib \
    --with-gmp-include=/usr/local/include \
    --with-gmp-lib=/usr/local/lib

make && make install
配置環(huán)境變量:
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64/:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/usr/local/include/:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/include/:$CPLUS_INCLUDE_PATH
更新動態(tài)庫的緩存:
ldconfig -v
編譯安裝GCC(先安裝完依賴包cloog,gmp,isl,mpc,mpfr):
wget ftp://ftp.gnu.org/gnu/gcc/gcc-6.3.0/gcc-6.3.0.tar.gz
tar xvf gcc-6.3.0.tar.gz
cd gcc-6.3.0
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make -j4
make install
查看gcc版本:
gcc --version



上一篇:CentOS使用Privoxy上網(wǎng)設(shè)置shadowsocks代理的方法
下一篇:CentOS6.10/7.6下Java8 Jdk+Tomcat環(huán)境安裝教程 開機啟動

相關(guān)熱詞搜索:gcc linux centos