CentOS 6.6升級GCC
昨天裝完Matlab以後,DPM compile報錯,下方錯的意思是需要支援c++11的g++。但是CentOS6 的預設gcc版本是4.4.7,支援c++11的版本是4.8.0以上(這裡不太確定)?所以這裡就需要手動更新GCC了。
Building with 'g++'.Error using mexcc1plus: error: unrecognized command line option "-std=c++11"
1、下載源碼
在這裡,穩妥起見,選擇了4.8.5,如果需要別的版本,改掉版本號碼就好了,可以去GCC官網查看
$ wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz
2、下載依賴包 & 預先安裝
編譯安裝 GCC 需要依賴mpc,mpfr,gmp包。好在 GCC 源碼裡內建指令碼可以輕鬆下載依賴包。
$ tar zxf gcc-4.8.5.tar.gz$ cd gcc-4.8.5$ ./contrib/download_prerequisites
在此指令碼裡可以看到依賴包的版本號碼依次是mpc-0.8.1,mpfr-2.4.2,gmp-4.3.2。
3、編譯安裝
$ cd .. //這樣做的原因主要是要在原始碼外建立build檔案夾$ mkdir gcc-build-4.8.5$ mkdir /usr/local/gcc-4.8.5 //放置的是 include 檔案。$ mkdir /usr/local/gcc //放置的是 bin + lib 檔案$ cd gcc-build-4.8.5$ ../gcc-4.8.5/configure --prefix=/usr/local/gcc-4.8.5 --exec-prefix=/usr/local/gcc --enable-languages=c,c++ //為了節省時間,這裡只編譯c和c++的$ make && make install
為了避免安裝後系統裡出現多個版本的 GCC,這裡直接將編譯安裝的目錄指定為/usr/local/gcc-4.8.5和/usr/local/gcc下,如果不指定–prefix,則會預設安裝到/usr/local下。
等待
make以後,漫長的等待,搞定
4、環境變數配置
將 gcc/g++改名,留存舊版本
$ mv /usr/bin/gcc /usr/bin/gcc-4.4.7$ mv /usr/bin/g++ /usr/bin/g++-4.4.7
$ export PATH=/usr/local/gcc/bin:$PATH # 使用最新的 gcc/g++;
確認版本號碼
$ g++ --version$ gcc --version$ which g++$ which gcc
錯誤1、Build檔案夾建立到錯誤的位置stubs-32.h 找不到,CentOS 是64位的
compilation terminated.make[5]: *** [_muldi3.o] Error 1make[5]: Leaving directory `/home/wei/gcc-4.8.5/gcc-build-4.8.5/x86_64-unknown-linux-gnu/32/libgcc'…………
解決方案:安裝 32 位的 glibc-devel,後面的參數是忽略某個軟體的多版本問題。
$ yum -y install glibc-devel.i686 --setopt=protected_multilib=false
這個錯主要原因是建立的build檔案夾在原始碼樹裡,需要在另外獨立的檔案夾使用。 解決方案是:在原始碼外建立了檔案夾,解決後的代碼已經更新到上面了。
First, wehighlyrecommend that GCC be built into a separate directory from the sources whichdoes not reside within the source tree. This is how we generally build GCC; building where srcdir == objdir should still work, but doesn’t get extensive testing; building where objdir is a subdirectory of srcdir is unsupported.
參考文獻
1、在CentOS下編譯安裝GCC 2、Installing GCC: Configuration
-
頂
-
0
-
踩