您的位置:首页 > 运维架构 > Linux

centos升级gcc到4.8.1(支持c++11)步骤

2014-04-23 12:30 288 查看
[root@localhost ~]#

下载gcc最新版

[root@localhost ~]# wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.1/gcc-4.8.1.tar.gz
然后解压到文件夹

[root@localhost ~]# tar -zxvf gcc-4.8.1.tar.gz

[root@localhost ~]# cd /root/gcc-4.8.1

[root@localhost ~]# ./contrib/download_prerequisites

[root@localhost contrib]# cd ..

[root@localhost ~]#mkdir build_gcc_4.8.1

[root@localhost build_gcc_4.8.1]# cd build_gcc_4.8.1

[root@localhost build_gcc_4.8.1]# ../gcc-4.8.1/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

[root@localhost build_gcc_4.8.1]# make -j

[root@localhost build_gcc_4.8.1]# make install
[root@localhost build_gcc_4.8.1]# ls /usr/local/bin | grep gcc



[root@localhost build_gcc_4.8.1]# /usr/sbin/update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/i686-pc-linux-gnu-gcc-4.8.1 40

[root@localhost build_gcc_4.8.1]# gcc --version

gcc (GCC) 4.8.1

Copyright © 2013 Free Software Foundation, Inc.

本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;

包括没有适销性和某一专用目的下的适用性担保。

[root@localhost build_gcc_4.8.1]# /usr/sbin/update-alternatives --install /usr/bin/g++ g++ /usr/local/bin/g++ 40

[root@localhost build_gcc_4.8.1]# g++ --version

g++ (GCC) 4.8.1

Copyright © 2013 Free Software Foundation, Inc.

本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;

包括没有适销性和某一专用目的下的适用性担保。

测试一下c++ 11的新功能:

#include <array>

#include <iostream>

using namespace std;

int main()

{

std::array<int, 3> arr = {2, 3, 5};

for(auto& s : arr){

cout << s << endl;

}

}

编译:

g++ test_11.c -std=gnu++0x或g++ test_11.c -std=c++0x

./a.out

输出:

2

3

5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: