首页 > 解决方案 > 打印 gcc 支持的最新 C++ 标准

问题描述

GCC 系列编译器接受一个参数来指定编译器可以使用的语言标准。

例如,gcc--std=gnu++20(或--std=gnu++2a)和gcc--std=gnu18

我期望的是一种bash打印本地支持的最新标准的方法(首选脚本)gcc。到目前为止,我什至找不到打印本地支持的所有标准的方法gcc

注意:不要与以下内容混淆,因为我要求的是最新标准而不是默认标准: 如何找出我的 gcc 默认使用的 ANSI C 标准?

标签: c++gcc

解决方案


非常感谢@ssbssa。这是按预期工作的 bash 脚本的草稿版本

gcc 10适用于 C++ 标准):

$ gcc -v --help 2>/dev/null | egrep "gnu\+\+[^I]+ISO [^1]"
  -std=gnu++11                Conform to the ISO 2011 C++ standard with GNU extensions.
  -std=gnu++14                Conform to the ISO 2014 C++ standard with GNU extensions.
  -std=gnu++17                Conform to the ISO 2017 C++ standard with GNU extensions.
  -std=gnu++20                Conform to the ISO 2020 C++ draft standard with GNU extensions (experimental and incomplete support).  Same as -std=gnu++2a.
  -std=gnu++2a                Conform to the ISO 2020 C++ draft standard with GNU extensions (experimental and incomplete support).

编辑:脚本的最终版本是:

$ gcc -v --help 2>/dev/null | egrep  "gnu\+\+[^I]+ISO [^1]" | egrep -o "\-[^ ]+" | tail -n 1
-std=gnu++2a

推荐阅读