主要参照以下两篇文章
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