Welcome reprint, Reproduced please specify the original address: http://blog.csdn.net/majianfei1023/article/details/46811159
The recent use of C + + 11, so there is no way to have to upgrade the centos6.6 gcc4.4.7.
The GCC compiler has gone to 5.1, but I am not particularly interested in the latest version and prefer a stable version.
gcc4.8.1 is the first compiler to fully support c++11, and my side is 4.8.2.
First, get the gcc4.8.2 package and unzip:
Download Link: http://gcc.skazkaforyou.com/releases
It has all the GCC versions and downloads it by itself.
You can also choose:
wgethttp://gcc.skazkaforyou.com/releases/gcc-4.8.2/gcc-4.8.2.tar.gz
then unzip: TAR-ZXVF gcc-4.8.2.tar.gz
Second, install the dependent library:
Enter the gcc-4.8.2 directory and execute the./contrib/download_prerequisities script will automatically download three dependent libraries for gmp-4.3.2,mpfr-2.4.2, mpc-0.8.1
or manually download it yourself:
ftp://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2
http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2
http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gz
Then there is the mechanical installation process.
CD gmp./configure--prefix=/usrsudo make && make INSTALLCD mpfr./configure--prefix=/usrsudo make && make INSTALLCD mpc./configure--prefix=/usrsudo make && make install
Note: g++-V can see the system's original GCC installation directory is the value of the --prefix variable (generally/user or/user/local), you install the same time as it is the best configuration, so the most convenient.
If you are compiling a custom specified installation path , you will have to put the Lib directory in ld.so.conf and execute ldconfig.
if not , you need to add the following options when compiling GCC:
installation directory for--WITH-MPC=MPC
installation directory for--WITH-MPFR=MPFR
installation directory for--WITH-GMP=GMP
three, compile and install GCC4.8.2
./configure--prefix=/usr--enable-threads=posix-- Disable-checking--enable-languages=c,c++--disable-multilib
sudo Make && make install
GCC:
--prefix //default GCC installation directory, Preferably the same as the original GCC installation directory
--disable-checking The compiler generated by //does not perform additional checks during compilation, or you can use--enable-checking=xxx to add some checks;
- -enable-languages //specifies which languages GCC can compile, separated by commas, such as C,c++,java
--disable-multilib //default GCC compiles the code into a 64-bit program on a 32-bit system, or compiles it to a 32-bit program on a 64-bit system, and if this compilation option is added, the cross-compilation feature of the GCC is turned off.
Note: If you are not in/usr or/user/local then link to the corresponding directory is OK.
Iv. success of the test
View GCC-V discovery has been successfully updated to 4.8.2
Perform an example:
#include <iostream> #include <vector> int main () {int arr[] = {2,4,6,8,10};size_t count=sizeof (arr)/sizeof ( Arr[0]);std::vector<int> VEC (Arr,arr + count);//for (Std::vector<int>::iterator iter = Vec.begin (); ITER! = Vec.end (); ++iter) for (Auto iter = Vec.begin (); ITER! = Vec.end (); ++iter) {Std::cout<<*iter<<std::endl;} return 0;}
g++ cpp11.cpp-o cpp11-std=c++11
If you do not add -std=c++11 will compile the error, because there is no way to identify auto ITER, this is the syntax of c++11.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux under compilation gcc4.8.2