C++ 如何检查我的 gcc 的版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35269922/
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-28 14:30:07  来源:igfitidea点击:

How to Check the Version of my gcc?

c++gcccentos7g++4.8

提问by Hei

In file included from /usr/include/c++/4.8.2/locale:41:0,
                 from /usr/include/c++/4.8.2/iomanip:43,
                 from [...omitted by myself as it is irrelevant]
/usr/include/c++/4.8.2/bits/locale_facets_nonio.h:59:39: error: ‘locale' has not been declared
     struct __timepunct_cache : public locale::facet

Above is the first error in my build log.

以上是我的构建日志中的第一个错误。

I didn't try to compile glibc/gcc myself, and I installed them via yum.

我没有尝试自己编译 glibc/gcc,我是通过 yum 安装的。

One fishy thing I found is:

我发现的一件可疑的事情是:

$ ll /usr/include/c++/
total 4
drwxr-xr-x. 12 root root 4096 Dec 17 14:16 4.8.2
lrwxrwxrwx   1 root root    5 Dec 17 14:16 4.8.5 -> 4.8.2
$

And yum showed only 1 version of gcc:

yum 只显示了 1 个版本的 gcc:

$ yum info gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.uhost.hk
 * epel: mirrors.hustunique.com
 * extras: centos.uhost.hk
 * updates: centos.uhost.hk
Installed Packages
Name        : gcc-c++
Arch        : x86_64
Version     : 4.8.5
Release     : 4.el7
Size        : 16 M
Repo        : installed
From repo   : base
Summary     : C++ support for GCC
URL         : http://gcc.gnu.org
License     : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
Description : This package adds C++ support to the GNU Compiler Collection.
            : It includes support for most of the current C++ specification,
            : including templates and exception handling.

Any idea how to verify the headers in /usr/include/c++/4.8.2 is indeed from 4.8.5 package?

知道如何验证 /usr/include/c++/4.8.2 中的头文件确实来自 4.8.5 包吗?

Thanks in advance.

提前致谢。

P.S. I think probably glibc is irrelevant but here is the info:

PS 我认为 glibc 可能无关紧要,但这里是信息:

$ ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 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.
Written by Roland McGrath and Ulrich Drepper.

回答by Jonathan Wakely

The symlink to the 4.8.2directory is nothing to worry about, it's normal for the libstdc++ headers on Red Hat Enterprise Linux (and therefore CentOS) to be arranged like that.

4.8.2目录的符号链接没有什么可担心的,Red Hat Enterprise Linux(以及 CentOS)上的 libstdc++ 标头这样排列是正常的。

gcc --versionwill tell you the version of the gccexecutable in your path.

gcc --version会告诉gcc您路径中可执行文件的版本。

rpm -q libstdc++-develwill tell you the version of the package that owns the C++ standard library headers.

rpm -q libstdc++-devel会告诉您拥有 C++ 标准库头文件的包的版本。

rpm -ql libstdc++-develwill list the files installed by that package, which will include the files under /usr/include/c++/4.8.2

rpm -ql libstdc++-devel将列出该软件包安装的文件,其中将包括以下文件 /usr/include/c++/4.8.2

rpm --verify libstdc++-develwill check that you haven't messed up the C++ headers by replacing them with something else.

rpm --verify libstdc++-devel将通过用其他东西替换它们来检查您是否没有弄乱 C++ 头文件。

The error is more concerning, that implies you have messed somethingup. My guess would be it's in the from [...omitted by myself as it is irrelevant]part, which may actually be very relevant. std::localeshould be declared in <bits/locale_classes.h>which is included before <bits/locale_facets_nonio.h>, so if it wasn't declared my guess is that you have some header that defines _LOCALE_CLASSES_Hand prevents the standard library header from being read. Do notdefine include guards that start with underscores, they are reserved names.

这个错误更令人担忧,这意味着你把事情搞砸了。我的猜测是它在from [...omitted by myself as it is irrelevant]部分中,这实际上可能非常相关。std::locale应该声明在<bits/locale_classes.h>which is included before <bits/locale_facets_nonio.h>,所以如果它没有声明,我的猜测是你有一些头文件定义_LOCALE_CLASSES_H并防止标准库头文件被读取。千万不能定义包括用下划线开始卫士,他们是保留名称

回答by Mandar

I am not quite sure but below is more information

我不太确定,但以下是更多信息

Stackoverflow: version of libc

Stackoverflow:libc 的版本

$ /lib/x86_64-linux-gnu/libc.so.6 
GNU C Library (Ubuntu EGLIBC 2.19-0ubuntu6) stable release version 2.19, by Roland McGrath et al.
Copyright (C) 2014 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.
Compiled by GNU CC version 4.8.2.
Compiled on a Linux 3.13.9 system on 2014-04-12.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs>.
mandar@ubuntu:~/Desktop$ 

回答by kiran

Since you are using Linux you can try

由于您使用的是Linux,您可以尝试

 ldd --version