gcc属于gun软件,下载gun所有软件
ftp://ftp.gnu.org/gnu/
ftp://ftp.gnu.org/gnu/gcc
1, 编译gcc的时候,还是需要存在gcc, g++
2, 等编译完成,卸载系统的gcc, g+++
3, 测试c++11
[chunli@CentOS ~]$ sudo yum install gcc gcc-c++
[chunli@CentOS ~]$ wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.bz2
[chunli@CentOS ~]$ tax xf gcc-4.8.5.tar.bz2
[chunli@CentOS ~]$ cd gcc-4.8.5
[chunli@CentOS gcc-4.8.5]$ ./contrib/download_prerequisites
[chunli@CentOS gcc-4.8.5]$ echo $?
[chunli@CentOS gcc-4.8.5]$ ./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
[chunli@CentOS gcc-4.8.5]$ echo $?
[chunli@CentOS gcc-4.8.5]$ make
[chunli@CentOS gcc-4.8.5]$ echo $?
[chunli@CentOS gcc-4.8.5]$sudo yum remove gcc g++ gcc-c++
[chunli@CentOS gcc-4.8.5]$ sudo make install
[chunli@CentOS gcc-4.8.5]$ echo $?
[chunli@CentOS gcc-4.8.5]$ logout #重新登录一次,识别新的gcc文件路径
chunli@linux:~$ ssh chunli@172.16.20.118
[chunli@CentOS ~]$ gcc --version
gcc (GCC) 4.8.5
[chunli@CentOS ~]$ g++ --version
g++ (GCC) 4.8.5
测试C++11
测试C++11
[chunli@CentOS ~]$ cat main.cpp
#include<iostream>
using namespace std;
int main( int argc, char** argv )
{
auto fn = []( int a, int b ){ return a + b; };
int c = fn( 2, 3 );
cout<<"result:"<<c<<endl;
return 0;
}
[chunli@CentOS ~]$ g++ -std=c++11 main.cpp && ./a.out
result:5
[chunli@CentOS ~]$