Compiling and installing GCC 5.2.0

Source: Internet
Author: User
Tags gmp

https://blog.atime.me/note/install-gcc-5.2.0-from-source.html 

Records problems and workarounds for compiling GCC 5.2.0 for future queries.

The usual server is CentOS5, with the GCC compiler released 8 years ago 4.1.2 version, completely unable to write c++11 code, because do not want to upgrade the operating system, have to download the source code to compile.

The installation process is very Dan Hurt, had to record.

Installing dependent libraries

GCC relies on GMP 4.2+, MPFR 2.4+ and MPC 0.8+, where the latest version of the installation is downloaded directly.

For the sake of convenience, all libraries are loaded directly into the corresponding directory under the/usr/local directory. (Do not do so in a production environment)

Installing GMP 6.0
wget Https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2tar xvf GMP-6.0.0A.TAR.BZ2CD gmp-6.0.0./configuremake- J4make Checkmake Install
Installing MPFR 3.1.3

MPFR relies on GMP.

wget Http://www.mpfr.org/mpfr-current/mpfr-3.1.3.tar.bz2tar xvf mpfr-3.1.3.tar.bz2cd mpfr-3.1.3./configure-- With-gmp-include=/usr/local/include     --with-gmp-lib=/usr/local/libmake-j4make Checkmake Install
Installing the MPC 1.0.3

The MPC relies on GMP and MPFR.

wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gztar xvf mpc-1.0.3.tar.gzcd mpc-1.0.3./configure--with-mpfr-include= /usr/local/include     --with-mpfr-lib=/usr/local/lib     --with-gmp-include=/usr/local/include     -- With-gmp-lib=/usr/local/libmake-j4make Checkmake Install
Installing GCC Compilation

It is recommended that you read the official installation documentation first.

Download gcc and unzip it.

wget Ftp://ftp.gnu.org/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.bz2tar xvf GCC-5.2.0.TAR.BZ2CD gcc-5.2.0

unset a number of system variables first to prevent some macros from being found.

unset Cplus_include_path Library_path

Configuring GCC

./configure     --with-gmp-include=/usr/local/include     --with-gmp-lib=/usr/local/lib     -- With-mpfr-include=/usr/local/include     --with-mpfr-lib=/usr/local/lib     --with-mpc-include=/usr/local/ Include     --with-mpc-lib=/usr/local/lib     --enable-languages=c,c++     --enable-threads=posix     -- Disable-multilib

Detailed configuration item descriptions can refer to the installation documentation, which compiles only C and C + + compilers.

Then make -j8 , enable multithreaded compilation.

Test

Install Dejagnu First: yum install dejagnu .

Then run the following command:

Make-j8 CHECK-GCC

To view test results:

./contrib/test_summary
Installation

If the compilation passes smoothly, make install you can.

GCC and g++ are installed to the /usr/local/bin directory by default, LIBGCC and libstdc++ are installed to /usr/local/lib64 (x64) by default.

Remember to lower the dynamic library cache.

Ldconfig
Problems you may encounter XXXX not defined

If you encounter a situation where a macro is not defined, unset C_INCLUDE_PATH try again.

Braced spec is invalid

Very Dan pain of a problem, search all over the net also did not see a more formal solution. Now looks more reliable method can refer to here, the specific operation is to manually change a specs file.

I'm here host-x86_64-unknown-linux-gnu/gcc/specs to change all of them %:sanitize(xxx) fsanitize=xxx .

Test c++11

Write a brain-crippled CPP test under the newly installed compiler.

#include <atomic>#include <regex>#include <iostream>UsingNamespaceStd;IntMain(){Atomic<LongLong>Num(1L<<14);cout<<++Num<<Endl;RegexR("[0-9]+]);StringS("0ABC11ABC222CBA");Sregex_iteratorIb(S.Begin(),S.End(),R);Sregex_iteratorIe;cout <<  "search numbers in:" << s << endlfor  (sregex_iterator i = ibi != ie++i) {cout < <  "match:" << i->str< Span class= "P" > () << endl}}             /span>                

Compile and run:

/usr/local/bin/g++-std=c++11 b.cpp-o bld_library_path=/usr/local/lib64./b

Compiling and installing GCC 5.2.0

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.