简体   繁体   中英

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

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.

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 .

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.

你应该试试这个

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

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

g++ -Dstd=c++11

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM