Original http://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.
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 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 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 install
Installing GCC Compilation
It is recommended that you read the official installation documentation first.
Download gcc and unzip it.
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.
<<iostream>using namespace Std;int main () { Atomic<<<cout < < + +Endl;}
Compile and run:
/usr/local/bin/g++-std=c++b.cpp-o bld_library_path=/usr/local/lib64
Compiling and installing GCC 5.2.0