简体   繁体   English

G++ 版本和标准选项

[英]G++ version and std option

I see one of my makefile and see the below command.我看到我的一个 makefile 并看到下面的命令。

g++-5 -std=c++11 

From what I understand, the std option represents this -据我了解, std 选项代表了这一点-

GCC supports different dialects of C++, corresponding to the multiple published ISO standards. GCC 支持不同的 C++ 方言,对应于多个已发布的 ISO 标准。 Which standard it implements can be selected using the -std= command-line option.可以使用 -std= 命令行选项选择它实现的标准。

What does -5 in the g++ command signifies? g++ 命令中的 -5 是什么意思?

The 5 almost certainly means the version of GCC, 5.something in this case. 5 几乎可以肯定意味着 GCC 的版本,在这种情况下是 5.something。

Having names like this makes it easier to mix different versions on the same system.使用这样的名称可以更轻松地在同一系统上混合不同版本。

You can confirm this by running您可以通过运行确认这一点

g++ --version

and you should get something like你应该得到类似的东西

g++ (GCC) 5.2.0 g++ (GCC) 5.2.0

You are correct about the -std option.您对 -std 选项是正确的。 In addition to released versions, there is often support for upcoming versions.除了已发布的版本,通常还支持即将发布的版本。 You can find a summary of the support here and the options such as -std=c++2a for features planned for C++20 here .您可以在此处找到支持的摘要,以及此处为 C++20 计划的功能的选项(例如-std=c++2a )。

g++ 旁边的参数 -n 表示您要编译代码的 GNU C++ 编译器版本

The -5 is part of the actual g++ executable's name. -5是实际 g++ 可执行文件名称的一部分。 The exact choice of name is essentially up to the maintainers of your operating system or distribution.名称的确切选择基本上取决于您的操作系统或发行版的维护者。 Naming the executable this way allows multiple GCC versions to be installed in parallel, a feature that is often useful, for example if you want to offer your software to a variety of users and want to make sure that different compiler versions can handle your code.以这种方式命名可执行文件允许并行安装多个 GCC 版本,这一功能通常很有用,例如,如果您想将您的软件提供给各种用户并希望确保不同的编译器版本可以处理您的代码。 For example, on one of my (slightly older) boxes I currently see例如,在我目前看到的一个(稍旧的)盒子上

$ ls -l /usr/bin/g++*
lrwxrwxrwx 1 root root      7 Apr  8  2014 /usr/bin/g++ -> g++-4.8
-rwxr-xr-x 1 root root 259176 Mar 20  2014 /usr/bin/g++-4.4
-rwxr-xr-x 1 root root 775888 May  7  2016 /usr/bin/g++-4.8
$ /usr/bin/g++-4.4 --version
g++-4.4 (Ubuntu/Linaro 4.4.7-8ubuntu1) 4.4.7
Copyright (C) 2010 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.

$ /usr/bin/g++-4.8 --version
g++-4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 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.

Different compiler versions not only have differing support regarding C++ standard features, they may also have different bugs or quirks.不同的编译器版本不仅对 C++ 标准特性有不同的支持,它们也可能有不同的错误或怪癖。

Regarding GCC's support for different versions of the C++ standard, see https://gcc.gnu.org/projects/cxx-status.html .关于 GCC 对不同版本的 C++ 标准的支持,请参见https://gcc.gnu.org/projects/cxx-status.html For example, some C++17 language features were only introduced in GCC 5.1.例如,一些 C++17 语言特性仅在 GCC 5.1 中引入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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