如何检查我的gcc版本?

9
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

以下是我的构建日志中的第一个错误。
我没有尝试自己编译glibc/gcc,而是通过yum安装它们。
我发现一个可疑的事情是:
$ 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
$

并且yum只显示了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.

有没有想法如何验证 /usr/include/c++/4.8.2 中的头文件确实来自 4.8.5 软件包?

先行致谢。

P.S. 我认为 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.

1
你是在问glibc还是gcc?问题标题与实际问题有所不同,请确定好。 - Jonathan Wakely
3个回答

13

符号链接指向4.8.2目录是正常的,这在Red Hat Enterprise Linux(因此也包括CentOS)上的libstdc++头文件排列方式中很普遍。

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

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

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

rpm --verify libstdc++-devel将检查您是否通过替换其他内容而弄乱了C++头文件。

错误更加令人担忧,这意味着您已经搞砸了某些事情。我猜测它在[...省略]部分中,这可能非常重要。 std::locale应该声明在<bits/locale_classes.h>中,在<bits/locale_facets_nonio.h>之前,所以如果它没有被声明,我的猜测是您有一些头文件定义了_LOCALE_CLASSES_H并防止标准库头文件被读取。不要定义以下划线开头的包含保护符,它们是保留名称


非常有用的信息。尽管我注释掉了#include <iomanip>(其中包括<locale>)和使用std::setfill()的一行代码,上面的错误就消失了。虽然还有一些与<locale>无关的错误。不确定是因为这些错误,gcc混淆并产生了上述错误的误报。 - Hei
你做错了什么。包含标准头文件不应该出现任何错误。 - Jonathan Wakely
如何检查我的gcc支持的最大C版本? - Sourav Kannantha B
@SouravKannanthaB 这是一个不同的问题,请不要在其他人的问题评论中提出不同的问题。您应该阅读您的gcc版本附带的文档以找到答案。 - Jonathan Wakely

2

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

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$ 

1
尽管标题有些令人困惑,但这个问题与glibc无关。 - Jonathan Wakely

0

由于您正在使用Linux,您可以尝试

 ldd --version

我稍微编辑了你的回答。OP正在调用yum,这是Linux的软件包管理器,因此“如果您正在使用Linux”是不必要的。我还添加了命令的示例输出。 - rbaleksandar
1
尽管标题有些混淆,但这个问题与glibc毫无关系。 - Jonathan Wakely

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接