Turn: Compile and install gcc under CentOS

Source: Internet
Author: User
Tags gmp

Ext.: https://teddysun.com/432.html

Compile and install GCC under CentOSTechnology Autumn Sui Yibing Released: 2015-09-02 Updated: 2015-09-02 6,519 times Onlookers 14 times spit Groove

We know that for GCC to install the default version number with Yum under CentOS, CentOS 5 is 4.1.2;centos 6 is 4.4.7;centos 7 is 4.8.3.
Most of the time in compiling and installing software requires a high version of GCC, otherwise it will be an error.
So how do I upgrade the GCC version?

The first thing to confirm is the GCC version number that you upgraded to.
The latest GCC version is now 5.2, and CentOS 7 is still using 4.8, so I chose to upgrade to 4.8.5 Based on compatibility considerations.
GCC Official website: https://gcc.gnu.org

Following the steps to compile and install GCC 4.8.5, it is important to note that prior to compiling and installing GCC, the system must first install the old version of GCC and the dependent libraries via Yum.
If it is compiled under the x86_64 system, you also need to install libgcc.i686 glibc-devel.i686.

Yum install-y gcc Texinfo-tex flex zip libgcc.i686 glibc-devel.i686

Of course, if it is installed under the CentOS 5 x86_64 system, it is the following command:

Yum install-y gcc Texinfo-tex flex zip libgcc.i386 glibc-devel.i386

At the same time, it should be noted that the compilation and installation of GCC memory is not less than 1gb,swap not less than 1GB, hard disk is not less than 10GB, otherwise it is very likely to exit the error.
After compiling and installing, the directory gcc-4.8.5 will be more than 5GB.

1. Download the source code

wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz

2, download the dependency package
Compiling and installing GCC requires a dependency on the MPC,MPFR,GMP package. Fortunately, the GCC source code comes with a script that can easily download dependent packages.

Tar zxf gcc-4.8.5.tar.gzcd gcc-4.8.5./contrib/download_prerequisites

In this script you can see that the version number of the dependent package is mpc-0.8.1,mpfr-2.4.2,gmp-4.3.2 in turn.

3. Compile and install

mkdir GCC-BUILD-4.8.5CD gcc-build-4.8.5. /configure--prefix=/usrmake && make install

In order to avoid multiple versions of GCC appearing in the system after installation, the compiled and installed directories are specified as/usr directly, and if –prefix is not specified, it will be installed by default under/usr/local.
GCC 4.8.5 Light Source code is 105MB, so you can foresee the entire compilation process takes a long time (about 2 hours or so).

4. View version number

GCC--VERSIONGCC (gcc) 4.8.5g++--versiong++ (gcc) 4.8.5which Gcc/usr/bin/gccwhich g++/usr/bin/g++

Note: This is a successful installation under CentOS 6.7 x86_64.

5. Test procedure
CD ~
Create a main.cpp file that reads as follows:

    #include <iostream>    using namespace std;    int main () {        cout << "Hello world!" << Endl;        return 0;    }


To compile the main.cpp, execute the following command:

g++ Main.cpp-o Main

To execute the generated file:
./main

The output is as follows:
Hello world!

Written in the last
To query the installation of the GCC package via the RPM command:
Rpm-qa | grep gcc

The output is as follows:
Gcc-4.4.7-16.el6.x86_64
Libgcc-4.4.7-16.el6.x86_64
libgcc-4.4.7-16.el6.i686
Gcc-c++-4.4.7-16.el6.x86_64

Therefore, after compiling and installing GCC from the above steps, use Yum Update or Yum to upgrade GCC commands.

Reprint Please specify: Autumn Ice» Build and install gcc under CentOS

Turn: Compile and install gcc under CentOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.