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

C++C++11Compiler ErrorsG++Std

C++ Problem Overview


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.

C++ Solutions


Solution 1 - C++

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 - C++

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 - C++

you should try this

g++-4.4 -std=c++0x or g++-4.7 -std=c++0x

Solution 4 - C++

I also got same error, compiling with -D flag fixed it, Try this:

g++ -Dstd=c++11

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1382306View Question on Stackoverflow
Solution 1 - C++antonijnView Answer on Stackoverflow
Solution 2 - C++stefanView Answer on Stackoverflow
Solution 3 - C++papoView Answer on Stackoverflow
Solution 4 - C++pankaj kushwahaView Answer on Stackoverflow