5

I just followed an answer to this question to update my gcc version to 4.8. 1 on Ubuntu 12.04, which I thought would support C++11. However it does not seem to.

When I try to compile something with -std=c++11 flag, I get this error:

cc1plus: error: unrecognized command line option ‘-std=c++11’

My gcc version is this:

gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)

My g++ version is this:

$ g++ -v
  ....
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

What could I be missing?

Edit: I was missing that I needed to update g++

It is easily achieved with a small modification to the code provided in the above mentioned answer. Just change gcc to g++.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.8
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
Akavall
  • 637
  • 2
  • 10
  • 27
  • 2
    Did you try with g++? What version of g++ do you have? – muru Sep 10 '14 at 14:13
  • 2
    @muru The term gcc has dual usage here. It is the name of the C compiler binary, but also stands for GNU Compiler Collection, of which both the gcc and g++ binaries are part of. The cc1plus binary, is for c++ though. – dobey Sep 10 '14 at 14:19
  • @dobey Okay, so? O.o – muru Sep 10 '14 at 14:25
  • 1
    The gcc and g++ packages are separate. Upgrade g++ as well. You have g++ v4.6 now, so c++-11 is not available. – muru Sep 10 '14 at 14:26
  • You should compile with -std=c++0x. see updated answer. – αғsнιη Sep 10 '14 at 14:38

1 Answers1

5

You have upgraded the C compiler, but not the C++ compiler. They are separate binary packages. You need to also install the g++-4.8 package to get the new version of the C++ compiler.

dobey
  • 40,982