提示C++编译器G++版本老
GNU GCC 获取GCC源码
编译安装过程较长,防止ssh连接中断建议使用screen
解压GCC
tar -xvf gcc-9.2.0.tar.gz
执行configure报错
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.
Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
MPC : ftp://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
GMP : ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.xz
MPFR : http://ftp.gnu.org/gnu/mpfr/mpfr-4.0.2.tar.gz
这里提供了几个最新版本的下载地址
创建一个临时目录temp并在temp下进行编译和安装
$tar -xvf gmp-6.1.2.tar.xz
$mkdir temp
$cd temp
$sudo ../gmp-6.1.2/configure --prefix=/usr/local/gmp-6.1.2
configure: summary of build options:
Version: GNU MP 6.1.2
Host type: haswell-pc-linux-gnu
ABI: 64
Install prefix: /usr/local/gmp-6.1.2
Compiler: gcc -std=gnu99
Static libraries: yes
Shared libraries: yes
$sudo make
$sudo make install
安装后可能会出现如下提示
----------------------------------------------------------------------
/bin/mkdir -p '/usr/local/gmp-6.1.2/include'
/bin/install -c -m 644 gmp.h '/usr/local/gmp-6.1.2/include'
make install-data-hook
make[4]: Entering directory `/home/jhsy/temp'
+-------------------------------------------------------------+
| CAUTION: |
| |
| If you have not already run "make check", then we strongly |
| recommend you do so. |
| |
| GMP has been carefully tested by its authors, but compilers |
| are all too often released with serious bugs. GMP tends to |
| explore interesting corners in compilers and has hit bugs |
| on quite a few occasions. |
| |
+-------------------------------------------------------------+
make[4]: Leaving directory `/home/jhsy/temp'
make[3]: Leaving directory `/home/jhsy/temp'
make[2]: Leaving directory `/home/jhsy/temp'
make[1]: Leaving directory `/home/jhsy/temp'
根据提示
sudo make install-data-hook
之后就只剩下
+-------------------------------------------------------------+
| CAUTION: |
| |
| If you have not already run "make check", then we strongly |
| recommend you do so. |
| |
| GMP has been carefully tested by its authors, but compilers |
| are all too often released with serious bugs. GMP tends to |
| explore interesting corners in compilers and has hit bugs |
| on quite a few occasions. |
| |
+-------------------------------------------------------------+
建议执行
make check
tar -xvf mpfr-4.0.2.tar.gz
cd mpfr-4.0.2.tar.gz
mkdir temp
cd temp
sudo ../configure --prefix=/usr/local/mpfr-4.0.2 --with-gmp=/usr/local/gmp-6.1.2
sudo make
sudo make check
sudo make install
指定gmp版本路径
--with-gmp=/user/gmp-6.1.0/gmp-6.1.0-obj
tar -zxvf mpc-1.1.0.tar.gz
cd mpc-1.1.0/
mkdir temp
cd temp
sudo ../configure --prefix=/usr/local/mpc-1.1.0 --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-4.0.2
sudo make
sudo make check
sudo make install
sudo vim /etc/ld.so.conf
添加
/usr/local/gmp-6.1.2/lib
/usr/local/mpfr-4.0.2/lib
/usr/local/mpc-1.1.0/lib
添加完成后保存执行
sudo ldconfig
由于之前解压过GCC,如果没有解压可以执行tar
tar -xvf gcc-9.2.0.tar.gz
进入目标并创建临时文件夹
cd gcc-9.2.0/
mkdir temp
cd temp
sudo ../configure --prefix=/usr/local/gcc-9.2.0 --enable-threads=posix --disable-checking --enable--long-long --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-4.0.2 --with-mpc=/usr/local/mpc-1.1.0
如果依然报错
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.
报错
checking for isl 0.15 or later... no
required isl version is 0.15 or later
The following languages will be built: c,c++,fortran,lto,objc
*** This configuration is not supported in the following subdirectories:
gnattools gotools target-libada target-libhsail-rt target-libphobos target-zlib target-libgo target-libffi target-liboffloadmic
(Any other directories should still work fine.)
checking for default BUILD_CONFIG... bootstrap-debug
checking for --enable-vtable-verify... no
/bin/ld: cannot find crt1.o: No such file or directory
/bin/ld: cannot find crti.o: No such file or directory
/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc_s.so when searching for -lgcc_s
/bin/ld: cannot find -lgcc_s
/bin/ld: cannot find -lc
/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc_s.so when searching for -lgcc_s
/bin/ld: cannot find -lgcc_s
/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
configure: error: I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.
下载安装isl
ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
tar -jxvf isl-0.18.tar.bz2
cd isl-0.18/
mkdir temp
cd temp
sudo ../configure --prefix=/usr/local/isl-0.18
sudo make
sudo make install
使用–with-isl=/usr/local/isl-0.18添加入ld.so.conf.d
sudo ../configure --prefix=/usr/local/gcc-9.2.0 --enable-threads=posix --disable-checking --enable--long-long --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-4.0.2 --with-mpc=/usr/local/mpc-1.1.0 --with-isl=/usr/local/isl-0.18
依然报错
checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... yes
checking for the correct version of mpc.h... yes
checking for the correct version of the gmp/mpfr/mpc libraries... yes
checking for isl 0.15 or later... yes
The following languages will be built: c,c++,fortran,lto,objc
*** This configuration is not supported in the following subdirectories:
gnattools gotools target-libada target-libhsail-rt target-libphobos target-zlib target-libgo target-libffi target-liboffloadmic
(Any other directories should still work fine.)
checking for default BUILD_CONFIG... bootstrap-debug
checking for --enable-vtable-verify... no
/bin/ld: cannot find crt1.o: No such file or directory
/bin/ld: cannot find crti.o: No such file or directory
/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc_s.so when searching for -lgcc_s
/bin/ld: cannot find -lgcc_s
/bin/ld: cannot find -lc
/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc_s.so when searching for -lgcc_s
/bin/ld: cannot find -lgcc_s
/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
configure: error: I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.
更改参数
sudo ../configure --prefix=/usr/local/gcc-9.2.0 --enable-threads=posix --disable-checking --enable--long-long --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-4.0.2 --with-mpc=/usr/local/mpc-1.1.0 --with-isl=/usr/local/isl-0.18 --disable-multilib
终于创建makefile了
checking where to find the target ranlib... host tool
checking where to find the target readelf... host tool
checking where to find the target strip... host tool
checking where to find the target windres... host tool
checking where to find the target windmc... host tool
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile
紧接着执行
sudo make
sudo make install
安装过程可能比较缓慢
经过了不断的Google,总于是花了两个小时把GCC的错误全部排除。