【学习记录】编译安装GCC6.5
编译image-builder时需要用到gcc6,而Ubuntu自带的gcc版本较高,所以尝试自行编译gcc6,做个记录
测试环境:WSL2 : Ubuntu18
下载gcc源码
可以选则在GNU官方镜像站下载,但比较慢,国内推荐其他镜像网站下载,比如清华源。
各个版本的gcc
https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc
点击这里直接下载6.5.0版本👇
https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-6.5.0/gcc-6.5.0.tar.xz
或者在终端运行
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-6.5.0/gcc-6.5.0.tar.xz
tar vxf gcc-6.5.0.tar.xz
cd gcc-6.5.0/
下载完成后直接解压准备编译安装,这个时候可以试着configure一下,发现缺少几个东西,分别是
GMP, MPFR, MPC
于是一个一个安装
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations. Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
http://gcc.gnu.org/install/prerequisites.html for additional info. If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files. They may be located in separate packages.
安装gmp,mpfr,mpc
如果没装这几个东西是不能成功配置的
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gmp/gmp-6.2.1.tar.bz2
tar vxf gmp-6.2.1.tar.bz2
cd gmp-6.2.1/
./configure --prefix=/usr/local/gmp-6.2.1
make -j8
sudo make install
这样gmp就装好了,接下来是mpfr
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/mpfr/mpfr-4.1.0.tar.xz
tar mpfr-4.1.0.tar.xz
cd mpfr-4.1.0/
这个时候先看一眼
./configure --help
(省略...)
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-gmp-include=DIR GMP include directory
--with-gmp-lib=DIR GMP lib directory
--with-gmp=DIR GMP install directory
--with-gmp-build=DIR GMP build directory (please read INSTALL file)
--with-mini-gmp=DIR use mini-gmp (sources in DIR) instead of GMP
(experimental, please read doc/mini-gmp file)
--with-mulhigh-size=NUM internal threshold table for mulhigh
--with-pic[=PKGS] try to use only PIC/non-PIC objects
(省略...)
注意**–with-gmp=DIR**这个选项,我们要把之前装gmp的目录赋值给它,总结一下就是这样
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/mpfr/mpfr-4.1.0.tar.xz
tar vxf mpfr-4.1.0.tar.xz
cd mpfr-4.1.0/
./configure --with-gmp=/usr/local/gmp-6.2.1 --prefix=/usr/local/mpfr-4.1.0
make -j8
sudo make install
最后安装mpc,注意要指定gmp和mpfr的安装路径,同样可以./configure --help来查看
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/mpc/mpc-1.2.1.tar.gz
tar vxf mpc-1.2.1.tar.gz
cd mpc-1.2.1/
./configure --prefix=/usr/local/mpc-1.2.1 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0
make -j8
sudo make install
编译gcc
最后回到gcc源码目录下,用./configure配置,注意指定gmp,mpfr,mpc的安装目录
./configure --prefix=/usr/local/gcc-6.5.0 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpc=/usr/local/mpc-1.2.1
make -j8
sudo make install