主要參照以下兩篇文章
https://www.cppfans.org/1719.html
https://blog.csdn.net/cybertan/article/details/8101883
- 下載最新GCC源碼: https://www.gnu.org/server/mirror.html
- 解壓縮,這里gcc.tar.gz是壓縮包的名字。
1 tar -xvf gcc.tar.gz > /dev/null
在后面加上 > /dev/null之后,只有錯誤信息會輸出到屏幕上,用於檢查解壓縮的過程中是否有錯誤。
- 運行download_prerequisites腳本,這個腳本會自動幫你下載所需要的依賴文件和庫
1 ./contrib/download_prerequisites - 建立一個文件夾用於編譯
1 mkdir build 2 cd build
- 運行configure
1 ../configure --prefix=$HOME/.local/ --enable-checking=release --disable-multilib - 編譯並安裝
1 make -j8 2 make install
- 安裝完成之后在.bashrc中把相應的路徑寫好。
注意事項:在開始編譯之前應該unset一些環境變量,參見
https://stackoverflow.com/questions/12255058/g-4-7-1-compilation-error-conflicting-types-for-strsignal
https://stackoverflow.com/questions/21685255/how-can-i-understand-these-dreadful-errors-when-building-gcc-4-8-2
1 unset LIBRARY_PATH CPATH C_INCLUDE_PATH PKG_CONFIG_PATH CPLUS_INCLUDE_PATH INCLUDE
