How to install and use GCC g++ v4.7 and C++11 on Ubuntu 12.04
来源:互联网 发布:新视野大学英语软件 编辑:程序博客网 时间:2024/06/10 20:02
- from: http://charette.no-ip.com:81/programming/2011-12-24_GCCv47/
- How to install and use GCC g++ v4.7 and C++11 on Ubuntu 12.04 (beta)
- 2011-12-24_GCCv47.cpp
Summary
I had a bit of extra spare time over the 2011 holiday season, and I wanted to test out some of the new C++11 features. But I know the old GCC C++ compiler I have installed in my usual LTS Ubuntu 10.04 development environment is out-of-date, so the first thing I needed to do is upgrade my OS and GCC to something decent. Here is how I accomplished this task.
Ubuntu 12.04 (beta)
First thing was to change my operating system. From Canonical, I downloaded the latest daily live .iso file. Here is a decent place to start looking:http://cdimage.ubuntu.com/daily-live/current/precise-desktop-amd64.iso. These live-cd images are a breeze to install using VirtualBox, and within 30 minutes I had a decent development environment installed.
Installing GCC v4.6
When Ubuntu 12.04 is first installed, it defaults to GCC v4.6. And just as important, it only includes the 'C' compiler, not the 'C++' compiler:
A number of development tools are referenced by the meta-package named build-essential, so I started by making sure this package is installed:
This gave me the expected GCC v4.6 C++ compiler:
Installing GCC v4.7
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:
Now take a look to see if we can find the GCC packages:
Install the GCC v4.7 C/C++ compilers with the following command:
Switching compilers
Installing the v4.7 compilers does not remove the previous v4.6 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:
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:
From this point forward, the only thing required when switching compilers is this (relatively) simple command:
Calling the C++ compiler with --version confirms the right version is correctly installed:
Testing compilers
The only thing left is to test if the new v4.7 compiler is working as expected. There are several convenient pages on the GNU GCC web site which lists which features of C++11 are supported in each version of the compiler:
- v4.3
- v4.4
- v4.5
- v4.6
- v4.7
Comparing the v4.6 and v4.7 page, one easy-to-test feature where support was first added in v4.7 is delegating constructors. So I wrote up a quick test, which I used to confirm the difference between the two compilers:
- How to install and use GCC g++ v4.7 and C++11 on Ubuntu 12.04
- How To Install and Use Memcache on Ubuntu 14.04
- How to Install and Use Python Pip on Ubuntu 14.04 and pip install pytz
- Ubuntu 14.04安装PostgreSQL How To Install and Use PostgreSQL on Ubuntu 14.04
- How to Configure, Install and Use libnefilter_queue on Linux
- How to Configure, Install and Use libnefilter_queue on Linux
- How to Install OpenCV 3.0 and Python 3.4+ on Ubuntu
- How to Configure and Install ownCloud on Ubuntu 16.04
- How To Install and Configure Elasticsearch on Ubuntu 14.04
- How to Install NixNote on Ubuntu 13.04, Ubuntu 12.10 and Ubuntu 12.04 via PPA
- How to install and use doxygen
- How to install and use selenium
- How To Install and Use Redis
- How To Install and Use Redis
- How to install gcc-arm-linux-gnueabihf on Ubuntu 12.04
- on Ubuntu 12.04 to install and setup the tomcat 7
- How to Install Python 3.3 on Ubuntu 13.04, 12.10 and 12.04
- How to Install Oracle VirtualBox 5.1 on Ubuntu 16.04 & 15.10 and Debian 8/7
- Java Thread
- C++之函数指针
- Java规则引擎工作原理及其应用(转)
- 关于java中边界值校验的问题
- java-synchronized修饰方法释疑
- How to install and use GCC g++ v4.7 and C++11 on Ubuntu 12.04
- java bingfa
- Java Code之线程(二)
- Good book about java
- MAPI
- Hibernate 第五讲 数据库Id生成策略 (1)
- DOS命令批量修改文件后缀名
- 对ACM的态度
- PHPUnit require_once()报错问题