Trying out gcc-4.8.0 on Ubuntu 13.04.

Trying out gcc-4.8.0 on Ubuntu 13.04.

gcc-4.8.0, which has the best “experimental support for C++ 11”, should be standard in the upcoming Ubuntu 13.10, but you can play around with it using a PPA:

sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update -y
sudo apt-get install g++-4.8

The regular “gcc” and “g++” are still symlinked to gcc 4.7,  so they get used by default. If you want 4.8 by default, do this:

cd /usr/bin
sudo ln -sf g++-4.8 g++
sudo ln -sf gcc-4.8 gcc
sudo ln -sf gcov-4.8 gcov

Revert with:

cd /usr/bin
sudo ln -sf g++-4.7 g++
sudo ln -sf gcc-4.7 gcc
sudo ln -sf gcov-4.7 gcov

To use it:

g++ -std=c++11 prog.cpp -o prog

To get Eclipse to compile c++11 and also get the CDT to resolve C++ libraries, follow these steps from http://stackoverflow.com/questions/17457069/enabling-c11-in-eclipse-kepler-cdt:

There’s two things you have to do, first you need to setup your compiler, then you need to setup CDT’s language processor. Since you didn’t mention which compiler you’re using, I’ll assume it’s GCC but the steps will be similar for other compilers. (Note that you need a compiler that supports C++11, of course.)

Setting up the compiler is fairly straightforward:

* Right click your project and click Properties
* Under C/C++ Build click Settings
* Under GCC C++ Compiler, click Miscellaneous
* In the Other Flags box, append “-std=c++11” to the list of tokens.
* Click Apply and OK

At this point you should be able to rebuild your project and get it to run. But CDT still may show errors for C++11 includes. Here’s how you can resolve that:

* Right click your project and click Properties
* Under C/C++ General click “Preprocessor Include Paths, Macros”
* Select the Providers tab
* There should be an item in the list that says something like “CDT GCC Built in Compiler Settings”. Select this entry.
* Under the list there’s an box that says “Command to get compiler specs.” Append “-std=c++11” to this.
* Click Apply and then OK.
* Back in your Eclipse workspace, select the Project Menu, C/C++ Index, and click “Re-resolve unresolved includes.”. You may also have to save and clean and do a full build.

If you’re building stuff that uses std::threads, you may still need to link in the pthreads library:

* Project -> Properties -> C/C++ Build -> Settings -> Tool Settings
* GCC C++ Linker -> Libraries -> + -> pthread -> OK

#C++11


LINK:

C++0x/C++11 Support in GCC – GNU Project – Free Software Foundation (FSF)

This post was originally published publicly on Google+ at 2013-08-24 02:38:17+0800

You may also like...