gcc 4.8.1 是第一個(gè)完全支持C++11 的編譯器。下文是如何在Ubuntu 12.04, Ubuntu 13.04 或 Ubuntu 12.10中通過PPA安裝GCC 4.8的步驟。PPA為Ubuntu用戶提供了GCC 4.7.3 和 GCC 4.8.1兩個(gè)版本。在Ubuntu12.04 LTS默認(rèn)安裝的是gcc4.6.3,該版本只支持部分c++11的特性,可以通過增加“-std=c++0x" 編譯選項(xiàng)來使用這些特性,但是對多線程庫的支持較差。你可以參考下文的步驟,來升級(jí)系統(tǒng)中的gcc,g++版本。
安裝步驟:
1) Ctrl+Alt+T打開終端,執(zhí)行如下命令adding PPA to your repositories:
test@test:/install$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
2) 安裝gcc 4.8 和 g++ 4.8
test@test:/install$sudo apt-get update; sudo apt-get install gcc-4.8 g++-4.8
3) 裝完后,依次執(zhí)行如下命令將系統(tǒng)默認(rèn)的gcc,g++編譯器版本設(shè)置為4.8版本
test@test:/install$sudo update-alternatives --remove-all gcc
update-alternatives: error: no alternatives for gcc.
test@test:/install$sudo update-alternatives --remove-all g++
update-alternatives: error: no alternatives for g++.
test@test:/install$sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
update-alternatives: using /usr/bin/gcc-4.8 to provide /usr/bin/gcc (gcc) in auto mode.
test@test:/install$sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
update-alternatives: using /usr/bin/g++-4.8 to provide /usr/bin/g++ (g++) in auto mode.
test@test:/install$sudo update-alternatives --config gcc
There is only one alternative in link group gcc: /usr/bin/gcc-4.8
Nothing to configure.
test@test:/install$sudo update-alternatives --config g++
There is only one alternative in link group g++: /usr/bin/g++-4.8
Nothing to configure.
4) 安裝完畢?,F(xiàn)在你的系統(tǒng)中已經(jīng)默認(rèn)使用gcc 4.8和g++ 4.8了。通過如下命令查看:
test@test:/install$g++ --version
g++ (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
test@test:/install$gcc --version
gcc (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
聯(lián)系客服