Linux offline manual installation and upgrade gcc

Preface

GCC can be used to compile programs in C/C++, FORTRAN, JAVA, OBJC, ADA and other languages. You can choose to install supported languages ​​as needed.
Check the current gcc version:

gcc --version

1. Download the source code

gcc-7.2.0 version: https://ftp.gnu.org/gnu/gcc/
Download dependencies, which depend on four tools gmp, isl, mpc, mpfr
gmp-6.1.0 version: https://ftp.gnu .org/gnu/gmp/gmp-6.1.0.tar.bz2
isl-0.16 version: http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure
mpc-1.0.3 version: https ://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
mpfr-3.1.4 version: 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 等

2. Offline installation and usage steps

1. Unzip

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.Installation

2.1 Install dependency packages

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

Confirm that gmp, mpfr, mpc and other packages have been installed and the versions are correct

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

2.2 Install gcc

Check the linux version uname -a
My version is
aarch64 GNU/Linux

#Add the corresponding version information when running configure, otherwise an error may be reported. Different Linux versions will be different
–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

After compilation, gcc is installed in usr/local/gcc_deps, the content is as follows
Insert image description here

2.3 Configure the gcc environment

If the installation location is not in /usr, you need to configure the corresponding environment.

When compiling gcc, the configure command changes –prefix=usr/local/gcc_deps to –prefix=/usr. The default configuration of gcc is under /usr, which directly replaces the original gcc version. If something goes wrong, it is difficult to recover.
Installed in other directories, you need to configure the gcc environment accordingly after installation.

Set in command line

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

Permanent setting

The LD_LIBRARY_PATH environment variable can be permanently set in a file such as .bashrc or .profile:

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

3. Solutions to various situations when installing gcc from source code

1. Command not found

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 Solutions

Retouch compiled files

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' was not found on the system, but version 1.15 of aclocal exists.
You can try re-touching a few compiled files.

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

Install the corresponding command

Download path: 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
    download path: https://ftp.gnu.org/gnu/texinfo/

  • help2man: can't get `–help' info from automake-1.15 Try
    reference link: https://www.jianshu.com/p/31a30a969a82

  • WARNING: 'aclocal-1.16' is missing on your system
    Reference link: https://blog.csdn.net/poem_2010/article/details/102527733

Guess you like

Origin blog.csdn.net/in_177/article/details/131931962