cc1plus: error: unrecognized command line option "-std=c++11" with g++

219,606

Solution 1

Seeing from your G++ version, you need to update it badly. C++11 has only been available since G++ 4.3. The most recent version is 4.7.

In versions pre-G++ 4.7, you'll have to use -std=c++0x, for more recent versions you can use -std=c++11.

Solution 2

Quoting from the gcc website:

C++11 features are available as part of the "mainline" GCC compiler in the trunk of GCC's Subversion repository and in GCC 4.3 and later. To enable C++0x support, add the command-line parameter -std=c++0x to your g++ command line. Or, to enable GNU extensions in addition to C++0x extensions, add -std=gnu++0x to your g++ command line. GCC 4.7 and later support -std=c++11 and -std=gnu++11 as well.

So probably you use a version of g++ which doesn't support -std=c++11. Try -std=c++0x instead.

Availability of C++11 features is for versions >= 4.3 only.

Solution 3

you should try this

g++-4.4 -std=c++0x or g++-4.7 -std=c++0x
Share:
219,606
Admin
Author by

Admin

Updated on May 05, 2020

Comments

  • Admin
    Admin almost 4 years

    I'm trying to compile using g++ and either the -std=c++11 or c++0x flags.

    However, I get this error

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

    g++ --version

    g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
    Copyright (C) 2006 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
  • stefan
    stefan about 11 years
    @Antonijn Correct, but not an option for everyone.
  • stefan
    stefan about 11 years
    @Antonijn: There is software which is incompatible with versions > 4.1. E.g. ABACUS informatik.uni-koeln.de/abacus/index.html Sadly enough I had to use it once.
  • chris
    chris about 11 years
    Is 4.8.0 like good to go, or is there an actual release in March or something?
  • antonijn
    antonijn about 11 years
    @chris I'm sorry, it should be 4.7, 4.8 is still in-development.
  • chris
    chris about 11 years
    @Antonijn, Ah, guess I'll wait a month or two. I prefer the stable releases, or whatever better word for it you want to use.
  • antonijn
    antonijn about 11 years
    @chris Yeah. Or you just wait for the linux mint update manager to inform you :)
  • antonijn
    antonijn about 11 years
    @JoeCoderGuy Yep, that's the one I'm using.
  • chris
    chris about 11 years
    Same here. I'm using 4.7.2.
  • Veda
    Veda over 7 years
    Why is this downvoted? What's wrong with the answer? Why doesn't this work?
  • scohe001
    scohe001 over 6 years
    @Veda for me at least (on gcc4.6.3), it definitely was not compiling with c++11. I wrote a simple 2 line program with std::vector<int> v = {1, 2, 3}; to test and it was throwing all sorts of errors over it (different errors than without the flag though, interestingly enough).
  • jwm
    jwm about 6 years
    @Veda while this answer will compile, it very likely doesn't do anything desirable. The -D command line argument is equivalent to inserting a #define in your source code. So this command is like having #define std c++11. Can you then imagine how std::string will be redefined to c++11::string? Not very useful at all.