cenos Upgrade g++ gcc(cc1plus: error: unrecognized command line option “-std=c++11”)

Building with ‘g++’.

Error using mex

cc1plus: error: unrecognized command line option “-std=c++11”

1, download the source code

is here. To be on the safe side, 4.8.5 is selected. If you need another version, just change the version number

$wget HTTP:// ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz
2. Download dependency package & pre-installed

compiling and installing GCC depends on the MPC, MPFR, GMP package. Fortunately, GCC source script can easily download the dependency package.

$tar ZXF gcc-4.8.5.tar. Gz

$CD GCC – 4.8.5

$ ./contrib/download_prerequisites

You can see in this script that the version Numbers of the dependent packages are MPC-0.8.1, MPFR-2.4.2, gMP-4.3.2, in that order.
3, $yum -y install glibc-devel. I686 –setopt=protected_multilib=false
4. Compile and install

$ cd .. // The main reason for doing this is to create the build folder outside of the source code

$mkdir GCC – build – 4.8.5

$mkdir /usr/local/gcc-4.8.5 // include file.

$mkdir/usr/local/GCC// placed bin +.lib file

$CD GCC – build – 4.8.5

$ ../gC-4.8.5 /configure –prefix=/usr/local/ gC-4.8.5 –exec-prefix=/usr/local/ GCC –enable-languages= C, C ++ // To save time, only C and C ++ are compiled here

$ make & & make install

in order to avoid multiple versions of GCC in the system after installation, the directory to compile and install is directly specified under /usr/local/4.8.5 and /usr/local/gcc. If no -prefix is specified, it will be installed under /usr/local by default.

to wait

make after a long wait, done

5, environment variable configuration

rename GCC /g++ and keep the old version

$mv /usr/bin/ GCC /usr/bin/ GCC -4.4.7

$mv /usr/bin/g++ /usr/bin/g++-4.4.7

$export PATH=/usr/local/ GCC /bin:$PATH # use the latest GCC /g++;

confirm version number

$ g++ –version

$ gcc –version

$ which g++

$ which gcc


1. Build folder to the wrong location stubs-32. H cannot be found, CentOS is 64 bit

compilation terminated.

make[5]: *** [_muldi3.o] Error 1

make[5]: Leaving directory ‘/home/wei/gcc-4.8.5/gcc-build-4.8.5/x86_64-unknown linux-gnu/32/libgcc’


solution: install a 32-bit glibb-devel that ignores multiple versions of a piece of software.

$ yum -y install glibc-devel.i686 –setopt=protected_multilib=false

is a new build folder in the source tree and needs to be used in a separate folder. The solution is to create a new folder outside of the source code, the resolved code has been updated to the above.

First, we highly recommend that GCC be built into a separate directory from the sources whichdoes not reside within the source tree. This is how we generally build GCC; Building where srcdir == objdir should still work, but doesn’t get extensive testing; building where objdir is a subdirectory of srcdir is unsupported.

Read More: