Install and compile gcc10.1.0 under Ubuntu16.04

I have it here myself, but I want to upgrade it. I refer to this website

GCC compiler download and installation tutorial (for Linux distributions)

First of all, make sure whether the linux you are currently using has a compiler

gcc --version

 You can see that I have installed a lower version here. If it is bash: /usr/bin/gcc: No such file or directory, then it has not been installed yet.

Express install (usually lower version)
apt-get install gcc
apt-get install gcc-c++

Manual installation (longer time)
install gcc-10.1.0

1. If the operating system used has an old version of the GCC compiler installed, there is no need to install it separately; otherwise, you need to run the following command first to install an old version of the GCC compiler:

apt-get install -y glibc-static libstdc++-static
apt-get install -y gcc gcc-c++

2. Download the source code package. I refer to the website, but I can’t open this website http://mirror.hust.edu.cn/gnu/gcc/

Then I searched for other download paths again,

gnu-gcc-gcc-10.1.0 installation package download_Open Source Mirror Station-Alibaba Cloud The gnu-gcc-gcc-10.1.0 installation package is an official open source image free download service provided by Alibaba Cloud, with over 100 million downloads per day, Alibaba The open source mirror site provides free CDN acceleration for hundreds of operating system mirrors and dependent package mirrors including the gnu-gcc-gcc-10.1.0 installation package, with high update frequency, stability and security. http://mirrors.aliyun.com/gnu/gcc/gcc-10.1.0/
This can be downloaded, I downloaded .xz

It takes a few seconds, pay attention to downloading later, but the command to decompress will be different later

3. After downloading, unzip it, use the rz command to transfer it to Linux, and then unzip it. Create a directory to unzip it yourself. Below I will decompress two different compressed packages. Pay attention to the suffix name of the compressed package

eruikeict@ubuntu:/$ cd usr/local/ 

tar -zxvf gcc-10.1.0.tar.gz

tar -xvJf gcc-10.1.0.tar.xz

4. Start to download the required hungry dependency packages. After a few minutes, I have entered the root user here.

root@ubuntu:/usr/local# cd gcc-10.1.0/
root@ubuntu:/usr/local/gcc-10.1.0# ./contrib/download_prerequisites

Note that you must observe the execution result of this command to ensure that it has successfully downloaded gmp, mpfr, mpc and other dependent packages before proceeding to the following installation steps.

start installation

5. Create a directory to store the files generated by compiling the GCC source package

root@ubuntu:/usr/local/gcc-10.1.0# cd ..

root@ubuntu:/usr/local# mkdir gcc-build-10.1.0

root@ubuntu:/usr/local# cd gcc-build-10.1.0/

6. Since the GCC compiler supports the compilation of multiple programming languages, in actual situations we may only need to compile 1 or 2 programming languages, so it is necessary to configure it. GCC can be configured to support compiling C and C++ languages ​​by executing the following commands:

root@ubuntu:/usr/local/gcc-build-10.1.0# ../gcc-10.1.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

7. After creating the makefile earlier, you can use the make command to compile the GCC source program (it’s been a long time here, and it’s best to do it when you’re off work. Some people have done it for six hours, anyway, I’ve done two half an hour):

root@ubuntu:/usr/local/gcc-build-10.1.0# make

8. Finally, execute the following command to install gcc: (I made a mistake above, and the installation is unsuccessful below, so I downloaded the .xz compressed package again)

root@ubuntu:/usr/local/gcc-build-10.1.0# make install

9. Restart the operating system and check whether it has been installed correctly

root@ubuntu:/usr/local/gcc-build-10.1.0# gcc --version

yeah~ 

Guess you like

Origin blog.csdn.net/m0_60027682/article/details/125738907