编译器标准支持(c++11、c++14、c++17)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34836775/
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
Compiler standards support (c++11, c++14, c++17)
提问by ?imon Hrabec
How do I find which standards my GCC compiler supports? I don't mean how do I find out at the compilation time what C++ standard is being used (checking defined constants), but before compiling, how can I check availible standards to use (for flag -std=c++??
)?
如何找到我的 GCC 编译器支持哪些标准?我的意思不是在编译时如何找出正在使用的 C++ 标准(检查定义的常量),但在编译之前,我如何检查可用的标准(对于 flag -std=c++??
)?
The information is not present in man g++
.
中不存在该信息man g++
。
I can check out my gcc version by g++ --version
besides manualy trying the options?
g++ --version
除了手动尝试选项之外,我还可以查看我的 gcc 版本吗?
Is it possible to find somewhere table of GCC versions and supported standards?
是否可以在某处找到 GCC 版本和支持标准的表格?
回答by Igor R.
This information is available on GCC official website. Here are the relevant tables:
此信息可在 GCC 官方网站上找到。以下是相关表格:
回答by oldMammuth
gcc and g++ do not have a command line option to check this out. It would be nice that the -v option would tell something about the supported standards. Instead you can check the online docs at gcc Standardsand the useful synopsis at cppreference.com.
gcc 和 g++ 没有命令行选项来检查这一点。如果 -v 选项能够说明所支持的标准,那就太好了。相反,您可以查看gcc 标准中的在线文档和cppreference.com 中的有用概要。
According to cppreference, full support of c++11 came with gcc 4.8.1;
根据cppreference,gcc 4.8.1 完全支持 c++11;
To have full support of c++14 (with some of the new features of c++17), instead, you need gcc 5.0 and above.
要完全支持 c++14(具有 c++17 的一些新功能),您需要 gcc 5.0 及更高版本。
回答by Ruby A. Rose
The comment that @oldMammuth made is almost correct, gcc
and g++
do actually have a way to print the language standards they supports. It's just not well documented. I'd say it was basically hidden if it wasn't listed in parentheses below the help text of the --help
argument. The way it's done is by going through the GNU compiler toolchain and asking the particular compiler instance you're using for it's --help
text. I actually just learned this after having to do this research for my own project, but in order to bundle a whole bunch of compilers under one program, gcc
and g++
do exactly that, they use the main executable to serve as a middleman for communicating with the compiler, assembler, and linker processes. In order to access the help text to get the supported language standards of a given compiler version, you have to ask the compiler, not gcc
or g++
.
@oldMammuth 发表的评论几乎是正确的,gcc
并且g++
确实有办法打印他们支持的语言标准。它只是没有很好的记录。如果它没有列在--help
参数帮助文本下方的括号中,我会说它基本上是隐藏的。它的完成方式是通过 GNU 编译器工具链并询问您为它的--help
文本使用的特定编译器实例。实际上,我是在为我自己的项目进行这项研究后才了解到这一点的,但为了将一大堆编译器捆绑在一个程序中,gcc
并且g++
要做到这一点,他们使用主可执行文件作为与编译器、汇编器和链接器进程通信的中间人。为了访问帮助文本以获取给定编译器版本支持的语言标准,您必须询问编译器,而不是gcc
或g++
。
Since at this point, I'm getting tired of typing both commands, the rest of this will assume we're using gcc
; despite the fact that both commands are virtually interchangeable and basically the same middleman with a different name.
由于在这一点上,我已经厌倦了输入这两个命令,其余的将假设我们正在使用gcc
; 尽管事实上这两个命令实际上是可以互换的,并且基本上是同一个中间人,但名称不同。
You can get the path to said compiler by using gcc -print-prog-name=cc1
. On my system this is /usr/lib/gcc/x86_64-linux-gnu/8/cc1
. Then, just call said executable with the --help
parameter, and you're all set! Beware, there are hundreds of help parameter entries.I actually recommend piping the output through grep
and using a regex to find them because otherwise there's so much extra information it's really annoying.
您可以使用gcc -print-prog-name=cc1
. 在我的系统上,这是/usr/lib/gcc/x86_64-linux-gnu/8/cc1
. 然后,只需使用--help
参数调用所述可执行文件,就可以了!请注意,有数百个帮助参数条目。我实际上建议通过管道输出grep
并使用正则表达式来查找它们,否则会有太多额外的信息真的很烦人。
ALTERNATIVELY:
或者:
You can use gcc -v --help
as stated in the gcc
help text, to print the help dialogues for each program in the given tool-chain. This does result in a lot more output however.
您可以gcc -v --help
按照gcc
帮助文本中的说明使用,为给定工具链中的每个程序打印帮助对话框。然而,这确实会导致更多的输出。
Again, my recommendation is to use a regex to search through the output and find the standard versions supported.
gcc
also supports more languages than C and C++, including but not limited to, Fortran and Go.
同样,我的建议是使用正则表达式来搜索输出并找到支持的标准版本。
gcc
还支持比 C 和 C++ 更多的语言,包括但不限于 Fortran 和 Go。