CentOS6 升級gcc版本以支持C++11

【轉自:https://blog.csdn.net/weixin_38642130/article/details/86412609

解決問題
在編譯安裝的時候碰到“configure: error: ***A compiler with support for c++11 language features is required.”
是因爲編譯器版本不支持c++11,所以需要安裝高版本gcc編譯器以支持c++11,下面採用編譯源碼方式安裝。
在編譯安裝高版本gcc編譯器時,碰到“gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0”,所以索性把所有依賴重新安裝一遍。使用編譯gcc源碼的方式安裝。

預裝環境
$ yum install -y gcc gcc-c++

源碼包下載鏈接:https://download.csdn.net/download/weixin_38642130/10915785
把源碼包上傳到/usr/local/software目錄

安裝gmp
$ cd /usr/local/software
$ tar -zxvf gmp-5.0.2.tar.gz 
$ cd gmp-5.0.2
$ ./configure --prefix=/usr/local/ && make && make install && echo "sayok "

安裝mpfr
$ cd ..
$ tar -zxvf mpfr-3.1.2.tar.gz 
$ cd mpfr-3.1.2
$ ./configure --prefix=/usr/local/ --with-gmp=/usr/local/ && make && make install && echo "say ok"

安裝mpc
$ cd ..
$ tar -zxvf mpc-0.9.tar.gz 
$ cd mpc-0.9
$ ./configure --prefix=/usr/local/ --with-gmp=/usr/local/ --with-mpfr=/usr/local/ && make && make install && echo "say ok"

安裝gcc
$ cd ..
$ tar -zxvf gcc-4.9.4.tar.gz
$ cd gcc-4.9.4
$ ./configure --prefix=/usr/local/gcc-4.9.4 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local
$ make && make install && echo "say ok"


編譯安裝過程一個多小時
卸載舊版本編譯器
$ yum remove gcc gcc-c++
$ ln -s /usr/local/gcc-4.9.4/bin/c++ /usr/bin/c++
$ ln -s /usr/local/gcc-4.9.4/bin/g++ /usr/bin/g++
$ ln -s /usr/local/gcc-4.9.4/bin/gcc /usr/bin/gcc
添加環境變量,修改profile文件,在最末添加如下兩句
$ vim /etc/profile
LD_LIBRARY_PATH=/usr/local/gcc-4.9.4/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
$ source /etc/profile

 

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