upgrading to a c++11 compiler(preferably gcc)

closed account (Dy7SLyTq)
so i am running ubuntu 12.04 and it does have a c++ compiler, however, it is giving errors and i think its because im using a range-based for loop. ive run sudo apt-get update but it dont work. how can i get it to run a c++11 source file?
$ g++ -std=c++11
closed account (Dy7SLyTq)
tried that:

dtscode@dtscode-Latitude-E6410:~/Desktop/Jade$ g++ -std=c++11 main.cpp -o jade
cc1plus: error: unrecognized command line option ‘-std=c++11’
$ g++ --version


Try -std=c++0x
Last edited on
closed account (Dy7SLyTq)
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

thanks for your time :)
According to http://gcc.gnu.org/gcc-4.6/cxx0x_status.html it should work.
If it doesn't, install a newer version (you may be able to enable a `testing' repository)
You should be able to install gcc-4.7 and set it as default http://askubuntu.com/questions/269257/how-to-activate-gcc-4-7-version

But may I ask why not dist-upgrade?
also you may try
ubuntu wheezy/sid

under it
gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
closed account (Dy7SLyTq)
@naraku: thanks ill try that. and i havent done dist-upgrade cause i didnt know that command. i took a break from linux and am having to relearn the commands

edit: do you mean distro upgrade to 13? because 12 has extended support
Last edited on
You need GCC 4.7 (or 4.8) for C++11 support.
You need 4.8.1 for (most of) C++11

As of GCC 4.8.1, GCC's C++11 mode implements all of the major features of the C++11 standard produced by the ISO C++ committee.

http://gcc.gnu.org/gcc-4.8/cxx0x_status.html

Andy
closed account (Dy7SLyTq)
thank you all
this was the method that i used to upgrade in my ubuntu distros to 4.7, both 12.04 and 13.04 which both had 4.6 by default.
1
2
3
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7 g++-4.7


then make 4.6 slave to 4.7, and change to 4.7
1
2
3
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7 
sudo update-alternatives --config gcc

and the like to upgrade from 4.7 to 4.8 also, or back again, whichever
Last edited on
Topic archived. No new replies allowed.