错误:未识别的命令行选项“-std=c+ 11”和g++

时间:2022-03-30 02:25:39

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

我正在尝试使用g++和-std=c++11或c++0x标志进行编译。

However, I get this error

但是,我得到了这个错误

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

g++ --version

g++ -版本

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.

4 个解决方案

#1


85  

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.

从您的g++版本来看,您非常需要更新它。c++ 11仅从g++ 4.3开始可用。最新版本是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.

在pre-G+ 4.7版本中,您必须使用-std=c++0x,对于更近期的版本,您可以使用-std=c++11。

#2


11  

Quoting from the gcc website:

从gcc网站上引用:

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.

c++ 11的特性可以作为“主线”GCC编译器的一部分在GCC的Subversion存储库的主干中以及在GCC 4.3中以及以后的版本中使用。要启用c++0x支持,请向您的g++命令行添加命令行参数-std=c++0x。或者,要启用GNU扩展,除了c++ 0x扩展之外,还可以在g++命令行中添加-std= GNU +0x。GCC 4.7和后来的支持-std=c++11和-std=gnu++11。

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

所以你可能会使用一个不支持-std=c++11的g++版本。尝试化c++ 0 x。

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

c++ 11特性的可用性仅适用于>= 4.3版本。

#3


3  

you should try this

你应该试试这个

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

#4


-4  

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

我也有同样的错误,用-D标记编译它,试试这个:

g++ -Dstd=c++11

g++ -Dstd = c + + 11

#1


85  

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.

从您的g++版本来看,您非常需要更新它。c++ 11仅从g++ 4.3开始可用。最新版本是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.

在pre-G+ 4.7版本中,您必须使用-std=c++0x,对于更近期的版本,您可以使用-std=c++11。

#2


11  

Quoting from the gcc website:

从gcc网站上引用:

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.

c++ 11的特性可以作为“主线”GCC编译器的一部分在GCC的Subversion存储库的主干中以及在GCC 4.3中以及以后的版本中使用。要启用c++0x支持,请向您的g++命令行添加命令行参数-std=c++0x。或者,要启用GNU扩展,除了c++ 0x扩展之外,还可以在g++命令行中添加-std= GNU +0x。GCC 4.7和后来的支持-std=c++11和-std=gnu++11。

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

所以你可能会使用一个不支持-std=c++11的g++版本。尝试化c++ 0 x。

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

c++ 11特性的可用性仅适用于>= 4.3版本。

#3


3  

you should try this

你应该试试这个

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

#4


-4  

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

我也有同样的错误,用-D标记编译它,试试这个:

g++ -Dstd=c++11

g++ -Dstd = c + + 11