Article source: www.softown.cn/post/141.ht…

CentOS 7 64-Bit system, gcc-4.9.4.tar.bz2.

I use CentOS 7 64-bit system, because in the system when the default installation GCC compiler version is V4.8.5, so to higher version you need to install GCC compiler.

Install GCC using yum

For Linux distributions with YUM, installing the GCC compiler becomes so easy. We just need to execute the following commands respectively:

 
Copy the code
Install GCC, the c++ compiler, and the kernel file under root accountCopy the code
<span style="color:#000000">su root</span>
Copy the code

yum -y install gcc gcc-c++ kernel-devel

Install GCC

However, the GCC installed with YUM is not the latest version of GCC, which is currently 4.9.4(GCC 4.8 starts to fully support the new features of C 11 and C++ 11). If we want to install the latest version of GCC, then we need to install GCC ourselves.

When I installed GCC for the first time, I searched the Internet for a large number of GCC installation and configuration tutorials. Many of the tutorials were so full of content that I got confused, and there were always various errors when compiling and installing GCC. A final look at the official documentation revealed that installing a new version of GCC on your own was not as complicated as the tutorials suggested (some of which involved modifying several configuration files).

Download the GCC installation file

Before installing GCC, of course, you should get the GCC installation file first. Here we go straight through the authorities

gcc.gnu.org/

ftp.gnu.org/gnu/gcc/

Download gcc-4.9.4.tar.bz2(86 MB). Of course, you can also download gcc-4.9.4.tar.gz(110 MB), but it is much bigger.

Preparation before compilation

To install GCC 4.8 and above, you need to install the C standard library and header files, as well as the older C ++ compiler. If you don’t have these on your computer, please execute the following command (of course you can use apt-get and other methods to install, if already installed, do not need to install again) :

 
Copy the code
<span style="color:#009900">Copy the code
<span style="color:#000000">su root</span>
Copy the code

yum install -y glibc-static libstdc++-static

<span style="color:#008000">Copy the code
yum -y install gcc gcc-c++ kernel-devel
Copy the code

Here, we unzip gcc-4.9.4.tar.bz2 to the /usr/local/src directory (you can specify other directories as well). The full tar command is:

Run the following command to decompress the GCC installation file: su root su rootCopy the code
Tar JXF gcc-4.9.4.tar.bz2 -c /usr/local/src-4.9.4.tar.bz2 -c /usr/local/srcCopy the code

/usr/local/ SRC /gcc-4.9.4 Next, we execute the following commands in sequence:

/contrib/download _tools CD /usr/local/src/gcc-4.9.4 /contrib/download_prerequisitesCopy the code

Install GCC requires downloading dependent files such as GMP, MPFR, and MPC. Running download_prerequisites will automatically download the software and unzip it to the current directory.

Install GCC

Then, you are ready to compile and install GCC. /usr/local/build/gcc-4.9.4 /usr/local/build/gcc-4.9.4 /usr/local/build/gcc-4.9.4 Then we execute the following commands in sequence:

mkdir /usr/local/build/

The mkdir/usr/local/build/GCC – 4.9.4

/usr/local/build/gcc-4.9.4 /usr/local/build/gcc-4.9.4 /usr/local/build/gcc-4.9.4 Pay attention to, /usr/local/ SRC /gcc-4.9.4/configure --enable-checking=release --enable-languages=c, C ++ /usr/local/ SRC /gcc-4.9.4/configure --enable-checking=release --enable-languages= C, C ++ --disable-multilib # Use the CPU's four cores to enable four threads. If you do not add -j4 to compile GCC source programs, it will take a long time. Note that make is executed in the build path. /usr/local/build/gcc-4.9.4 /usr/local/build/gcc-4.9.4 Pay attention to, /usr/local/ SRC /gcc-4.9.4/configure --enable-checking=release --enable-languages=c, C ++ /usr/local/ SRC /gcc-4.9.4/configure --enable-checking=release --enable-languages= C, C ++ --disable-multilib # Use the CPU's four cores to enable four threads. If you do not add -j4 to compile GCC source programs, it will take a long time. Note that make is executed in the build path.Copy the code
make -j4
Copy the code
GCC make install make installCopy the code

The process of executing the make command may take a lot of time, and it took me more than 20 minutes to compile it. After executing the above commands, our GCC has been successfully installed.

Once the installation is complete, point to the working path and the terminal executes the command gedit ~/. Bash_profile or vim ~/. Bash_profile (this step feels unnecessary!! Usr /local/lib,lib64,bin, etc. Usr /local/lib,lib64,bin, etc.

In the ~/.bash_profile configuration library file and header file path (this step feels unnecessary!!)

exportLD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64/:$LD_LIBRARY_PATH

exportC_INCLUDE_PATH=/usr/local/include/:$C_INCLUDE_PATH

exportCPLUS_INCLUDE_PATH=/usr/local/include/:$CPLUS_INCLUDE_PATH

The last

gcc -v

 

`gcc -print-prog-name=cc1plus` -v

`g++ -print-prog-name=cc1plus` -v

 

You can view the version of GCC on the terminal, which has been updated to V4.9.4.

 

 

Unlike other tutorials, this tutorial does not decompress and compile GMP, MPFR, or MPC software respectively. Instead, download_Prerequisites is used to download and decompress the tool, and GCC is used to compile and install the tool. This is also an official recommended practice (Download_Prerequisites will also decide whether to enable Graphite cycle optimization based on the actual situation).

If your Linux system does not have a direct Internet connection, you have to open the file Download_Prerequisites, get links to these files, and then download the software from another internet-connected device. /usr/local/ SRC /gcc-4.9.4

 

 

——

 

GCC compiler configuration parameter description:

–enable-languages // Specifies which languages GCC can compile. Each language is separated by commas, such as C, C ++, and Java

–disable-multilib // By default, GCC can compile code into 64-bit programs on 32-bit systems, or into 32-bit programs on 64-bit systems. This compiler option disables cross-compilation of GCC.

 

Resources: CentOS7 install GCC 4.9.3