Chinaunix首页 | 论坛 | 博客
  • 博客访问: 339518
  • 博文数量: 88
  • 博客积分: 1695
  • 博客等级: 上尉
  • 技术积分: 1380
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-06 15:48
个人简介

喜欢美食, 旅行..

文章分类

全部博文(88)

文章存档

2014年(2)

2013年(12)

2012年(14)

2010年(8)

2009年(52)

我的朋友

分类: C/C++

2012-11-18 00:33:47

Step 1. Install the operating system.
You can download the current version ubuntu on the web-site "http://cdimage.ubuntu.com/daily-live/current/".

Step 2. Make sure the meta-package named "build-essential" has been install correct in the ubuntu system.

  1. $ sudo apt-get install build-essential

Step 3. Add the necessary PPA on the ubuntu system.
A quick search on Google turned up a PPA with the newer GCC v4.7, which has support for nearly all the new C++11 features. Add this PPA with the following commands:

  1. $ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
  2. $ sudo apt-get update

Step 4. Install the GCC v4.7 C/C++ compilers.

  1. $ sudo apt-get install gcc-4.7 g++-4.7
Step 5. Switching compilers.
Installing the v4.7 compilers does not remove the previous version compiler. This is very important, if you skipped the previous sentence, now is a good time to go back and re-read it! The system now has 2 'C' compilers and 2 'C++' compilers:

  1. $ which g++
  2. /usr/bin/g++
  3. $ ls -lh /usr/bin/g++
  4. lrwxrwxrwx 1 root root 7 Dec 12 17:04 /usr/bin/g++ -> g++-4.6
  5. $ ls -lh /usr/bin/g++*
  6. lrwxrwxrwx 1 root root 7 Dec 12 17:04 /usr/bin/g++ -> g++-4.6
  7. -rwxr-xr-x 1 root root 349K Dec 17 04:17 /usr/bin/g++-4.6
  8. -rwxr-xr-x 1 root root 566K Dec 22 02:37 /usr/bin/g++-4.7
Luckily, there is a very simple and standard method for switching between applications that provide identical (or near-identical) functionality: update-alternatives. If you've never had to use this before, go ahead and run man update-alternatives.

We need to let update-alternatives know we have 2 C/C++ compilers, create a record for each one, and then configure which one we want to use. This is done with the following:

  1. $sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
  2. $sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
  3. $sudo update-alternatives --config gcc
Note the use of "slave". This ensures when we change the configuration for gcc, that we automatically update the configuration for g++. This is important so the compilers aren't out-of-sync.
From this point forward, the only thing required when switching compilers is this (relatively) simple command:

  1. $sudo update-alternatives --config gcc
Calling the C++ compiler with --version confirms the right version is correctly installed:

  1. $ g++ --version
  2. g++ (Ubuntu/Linaro 4.7-20111222-0ubuntu1) 4.7.0 20111222 (experimental) [trunk revision 182617]

Step 6. Test the compilers.
I will not say anything about it. The reader can code and test the C++11 features himself.

Reship from 
阅读(1644) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~