cc1plus:错误:无法识别的命令行选项“-std=c++11”与 g++

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14674597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:34:39  来源:igfitidea点击:

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

c++c++11compiler-errorsg++std

提问by antonijn

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

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

However, I get this error

但是,我收到此错误

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

g++ --version

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.

回答by antonijn

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.

在 G++ 4.7 之前的版本中,您必须使用-std=c++0x,对于较新的版本,您可以使用-std=c++11.

回答by stefan

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 支持,请将命令行参数 -std=c++0x 添加到 g++ 命令行。或者,要启用除 C++0x 扩展之外的 GNU 扩展,请将 -std=gnu++0x 添加到您的 g++ 命令行。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++0xinstead.

所以可能你使用的 g++ 版本不支持-std=c++11. 试试吧-std=c++0x

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

C++11 功能的可用性仅适用于 >= 4.3 的版本。

回答by papo

you should try this

你应该试试这个

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

回答by pankaj kushwaha

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

我也遇到了同样的错误,用 -D 标志编译修复了它,试试这个:

g++ -Dstd=c++11

g++ -Dstd=c++11