linux离线手动安装升级gcc

前言

GCC可以用来编译C/C++、FORTRAN、JAVA、OBJC、ADA等语言 的程序,可根据需要选择安装支持的语言。
查看当前gcc版本:

gcc --version

一、下载源码

gcc-7.2.0版本:https://ftp.gnu.org/gnu/gcc/
下载依赖,共依赖四个工具gmp、isl、mpc、mpfr
gmp-6.1.0版本:https://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.bz2
isl-0.16版本: http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure
mpc-1.0.3版本 :https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
mpfr-3.1.4版本:https://ftp.gnu.org/gnu/mpfr/mpfr-3.1.4.tar.gz

提示:对应不同版本的gcc,对应的依赖版本可能也不一样,具体版本查看gcc-7.2.0/contrib/download_prerequisites

有网络的Linux 安装 gcc 的时候直接执行 ./contrib/download_prerequisites,自带下载安装依赖:mpfr、mpc、gmp 等

二、离线安装使用步骤

1.解压

tar -zxvf gcc-7.2.0.tar.gz
tar -xf mpfr-3.1.4.tar.gz
tar -xf isl-0.16.tar.bz2
tar -xf mpc-1.0.3.tar.gz
tar -xf gmp-6.1.0.tar.bz2

2.安装

2.1安装依赖包

cd gmp-6.1.0  && ./configure && make && make install
cd mpfr-3.1.4 && ./configure && make && make install
cd isl-0.16   && ./configure && make && make install
cd mpc-1.0.3  && ./configure && make && make install

确认 gmp, mpfr, mpc 等包已经安装,并且版本正确

rpm -qa | grep gmp
rpm -qa | grep mpfr
rpm -qa | grep mpc

2.2安装gcc

查看linux版本 uname -a
我的版本是
aarch64 GNU/Linux

#运行configure时加上对应版本的信息,不然可能会报错,linux版本不同会有所区别
–build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu

mkdir build			   //不能在source目录下configure 
cd build	
                          
$PWD/../gcc-7.2.0/configure --prefix=/usr/local/gcc_deps --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu

   // 不运行这个$PWD/../gcc-7.2.0/configure --prefix=usr/local/gcc_deps
make
make check
make install

编译好后,gcc安装到了usr/local/gcc_deps,内容如下
在这里插入图片描述

2.3配置gcc环境

如果安装位置不是在/usr,需要配置对应的环境

编译gcc时configure命令把–prefix=usr/local/gcc_deps改为–prefix=/usr,gcc默认配置在/usr下,直接替换了原先的gcc版本,出了问题难恢复。
安装在其他目录下,需安装后对应配置gcc环境

在命令行中设置

export PATH=/usr/local/gcc_deps/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/gcc_deps/lib64:$LD_LIBRARY_PATH

永久设置

可以在.bashrc或.profile等文件中永久设置LD_LIBRARY_PATH环境变量:

echo 'export LD_LIBRARY_PATH=/usr/local/lib' >> ~/.bashrc

三、源码安装gcc各种情况的解决

1. 未找到命令

1.1 XXX is missing on your system.

...行81: makeinfo:未找到命令
WARNING: 'makeinfo' is missing on your system.
         You should only need it if you modified a '.texi' file, or
         any other file indirectly affecting the aspect of the manual.
         You might want to install the Texinfo package:
         <https://www.gnu.org/software/texinfo/>
         The spurious makeinfo call might also be the consequence of
         using a buggy 'make' (AIX, DU, IRIX), in which case you might
         want to install GNU make:
         <https://www.gnu.org/software/make/>
         ...

1.2 解决方法

重新touch编译文件

WARNING: 'aclocal-1.14' is missing on your system.
You should only need it if you modified 'acinclude.m4' or 'configure.ac' or m4 files included by 'configure.ac'. The 'aclocal' program is part of the GNU Automake package: It also requires GNU Autoconf, GNU m4 and Perl in order to run: make[1]: *** [aclocal.m4] Error 127

系统中没有找到’aclocal-1.14’,但存在1.15版本的aclocal。
可以试一下重新touch几个编译文件

touch configure.ac aclocal.m4 configure Makefile.am Makefile.in

安装对应命令

下载路径:https://ftp.gnu.org/gnu/texinfo/

tar zxvf texinfo-5.2.tar.gz
cd texinfo-5.2
./configure --prefix=/usr
make
make check
make install
  • makeinfo
    下载路径:https://ftp.gnu.org/gnu/texinfo/

  • help2man: can’t get `–help’ info from automake-1.15 Try
    参考链接:https://www.jianshu.com/p/31a30a969a82

  • WARNING: ‘aclocal-1.16’ is missing on your system
    参考链接:https://blog.csdn.net/poem_2010/article/details/102527733

猜你喜欢

转载自blog.csdn.net/in_177/article/details/131931962