Gcc-4.7.4, centosgcc-4.7.4 compiled under CentOS 6.6x64

Source: Internet
Author: User
Tags gmp

Gcc-4.7.4, centosgcc-4.7.4 compiled under CentOS 6.6x64

Recently, gcc of the old version found some problems, so I tried to upgrade it.

After reading some tutorials, I tried it and found that all the tutorials had some minor problems. So I will record my process here.

I would like to express my gratitude for the following articles for reference during compilation:

Http://blog.csdn.net/dyllove98/article/details/8917485

Http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/05/2199530.html

Http://www.linuxidc.com/Linux/2015-01/112595.htm

Now, let's go to the topic.

1. Preparations

Download the desired gcc version from the official gcc ftp. The gcc version I downloaded is 4.7.4 and 4.9.3 and 5.3.0.

Http://ftp.gnu.org/gnu/gcc/

Download a bz2 compressed package of version 4.7.4, and decompress the package after the download is completed:

$ tar -xf gcc-4.7.4.tar.bz2$ cd gcc-4.7.4

 

2. Compile the dependent Library

After the code is downloaded, some dependent libraries are required for gcc compilation. Among them, gmp, mpfr, and MCM are key libraries. The three libraries should be installed and downloaded in sequence. The download method is relatively simple, and the following code is done.

./contrib/download_prerequisites

Then, compile the three key libraries (because the installation of the Library requires the root permission, switch to the root permission first ):

(1) install gmp4.3.2 # cd gmp #. /configure -- prefix =/usr/local/gmp # make (compile) # make install (execute installation) (2) install mpfr # cd .. /mpfr #. /configure -- prefix =/usr/local/mpfr -- with-gmp =/usr/local/gmp (add the dependency Option When configuring) # make install (3) install mpc0.8.1 # cd .. /nm #. /configure -- prefix =/usr/local/MCM -- with-gmp =/usr/local/gmp -- with-mpfr =/usr/local/mpfr # make install

  
In step 1, the gmp database may fail to be found. Pay special attention to the two subtraction symbols before the with command.

At the same time, if the error still persists, we recommend that you set the environment variable LD_LIBRARY_PATH. In this example, insert several lines of code at the end of/etc/profile and update the Code:

# vim /etc/profile# LD_LIBRARY_PATH=/usr/local/gmp/lib:/usr/local/pfmr/lib:/usr/lib/mpc/lib:${LD_LIBRARY_PATH}export LD_LIBRARY_PATH# source /etc/profile

3. Compile gcc

Note that configure is directly carried out in the gcc code directory. Otherwise, the gmp library may fail to be found or you are prompted to execute make distclean.

To speed up compilation, you can add-j16 (value 16) after the make command to indicate the number of threads. According to your machine settings, some machines can be compiled in about 15 minutes.

# ./configure --prefix=/usr/local/gcc-4.7.4 --enable-threads=posix --disable-multilib -enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc# make -j16 # make install

The compilation is successful, and there are no error messages. The Leaving directory words indicate that the compilation is successful.

Then execute make install.

The installation directory is as follows:

# make install# ls /usr/local/gcc-4.7.4/bin  include  lib  lib64  libexec  share

 

4. Default gcc version settings

Refer to this article to set the default gcc: http://www.linuxidc.com/Linux/2012-10/72284.htm

First, check the path of the original gcc:

$ witch gcc

On my system, the above command shows:/usr/bin/gcc, that is, the original gcc command is in the/usr/bin directory.

To enable the original gcc to still be used, rename gcc/g ++:

 

# mv /usr/bin/gcc /usr/bin/gcc-4.4# mv /usr/bin/g++ /usr/bin/g++-4.4 

  

Create an optional link for different gcc versions (for g ++ operations, replace the corresponding gcc with g ++ ):

# Sudo update-alternatives -- install/usr/bin/gcc/usr/local/gcc-4.7.4/bin/gcc 50 # sudo update-alternatives -- install/usr/bin/gcc/ usr/local/gcc-4.9.3/bin/gcc 40 # sudo update-alternatives -- install/usr/bin/gcc/usr/bin/gcc-4.4 30 # sudo update-alternatives -- config gcc total the three programs provide "gcc ". Select command --------------------------------------------- * + 1/usr/local/gcc-4.7.4/bin/gcc 2/usr/local/gcc-4.9.3/bin/gcc 3/usr/bin/gcc-4.4

If you want to delete an option, you can execute a command similar

$ sudo update-alternatives --remove gcc /usr/bin/gcc-4.4

  

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.