C++ g++;不包括它所说的用于C++;11? 短版

C++ g++;不包括它所说的用于C++;11? 短版,c++,gcc,c++11,centos,centos6.5,C++,Gcc,C++11,Centos,Centos6.5,当我使用C++11标准的特性(std::stod函数)编译一个简单的代码时,GCC 4.9.1失败,出现以下错误: example.cpp: In function 'int main()': example.cpp:10:18: error: 'stod' is not a member of 'std' double earth = std::stod (orbits,&sz); ^ example.cpp:11:17: error: 'st

当我使用C++11标准的特性(std::stod函数)编译一个简单的代码时,GCC 4.9.1失败,出现以下错误:

example.cpp: In function 'int main()':
example.cpp:10:18: error: 'stod' is not a member of 'std'
   double earth = std::stod (orbits,&sz);
                  ^
example.cpp:11:17: error: 'stod' is not a member of 'std'
   double moon = std::stod (orbits.substr(sz));
                 ^
什么

我使用的命令是
g++-std=c++11 example.cpp

这是测试代码(在其他系统上编译得很好):

g++-v
使用系统GCC在两个集群上给出相同的输出,除了集群1上说它是
GCC版本4.4.7 20120313(Red Hat 4.4.7-3)(GCC)
和集群2上说
GCC版本4.4.7 20120313(Red Hat 4.4.7-4)(GCC)

我正在尝试使用
g++-std=c++11-save temps-MD example.cpp进行调试,以获取更多信息。。。这提供了一些线索,但我不知道从这里可以走到哪里

群集1上的中间(
.ii
)文件缺少一些行,例如(摘自
diff
ing
.ii
文件):

我很好奇
cpp
是否在所有错误的位置查找包含,但这似乎是合法的(
cpp-v
):

#包含搜索从这里开始:
/home/andyras/bin/gcc-4.9.1/include
/home/andyras/bin/gcc-4.9.1/include/c++/4.9.1/
/home/andyras/bin/gcc-4.9.1/include/c++/4.9.1/x86_64-unknown-linux-gnu/
/home/andyras/bin/gcc-4.9.1/lib/gcc/x86_64-unknown-linux-gnu/4.9.1/include
/usr/本地/包括
/home/andyras/bin/gcc-4.9.1/lib/gcc/x86_64-unknown-linux-gnu/4.9.1/include-fixed
/usr/包括
搜索列表结束。
这是一个非常令人沮丧的几个小时试图追查问题的根源。当然,我可以使用类似于
atof(myString.c_str())
的东西,而不是
std::stod
,但我想知道是否有一个潜在的问题会影响使用c++11其他部分的未来项目


如果您能提供更多的线索或见解,我们将不胜感激。

您已经做了所有必要的准备工作,以确定根本原因。您已经知道答案了:您已经发布了自定义gcc安装在“集群1”和“集群2”(非工作和工作构建)上的行为之间的明显差异

所以,这两个gcc安装之间有明显的不同;如果一个编译、链接和运行某些代码,而另一个却被完全相同的代码阻塞。不幸的是,很难确定事情会偏离轨道。之前,我自己已经构建了gcc,我可以说gcc是一个非常难安装且非常易变的包。例如,在连接一些C++代码后,几天来追寻一个神秘的失败,我最终把它转到GCC,在GCC的配置脚本中拾取错误版本的BIUTILS,并在内部关闭一些模糊的特性,最终表现为不是GCC的链接失败,而是GCC建立的东西。gcc自己建造、安装,毫无怨言,但它被破坏了

因此,我认为gcc本身的构建和安装没有明显问题,这完全不令人惊讶,也完全合理,但它已经被破坏,并将以这种方式阻塞有效代码

我的猜测是,您被破坏的gcc构建使用了一个被破坏的默认包含路径——它在
/usr/include
中查找头,而不是您自己的自定义安装目录。这是最有可能的答案,但它可能真的是任何东西。

很明显,你(就像你自己写的那样)有两个不同版本的gcc(一个版本是4.4.7-3,另一个版本是4.4.7-4),而且它们在编译代码时似乎有(尽管有点)差异


正如我在某个地方读到的,C++11标准尚未完全包含在所有编译器中,因此这似乎是一个集群的原因。另一个集群(您可能知道为什么)有一个包含更多新标准的版本,而且由于您希望您完全使用此功能,我建议您也在另一个集群上安装此版本。

不久前我也遇到过同样的问题,这是因为我遗漏了“-std=c++11”。我知道你说你有这个,但也许再检查一下?也许试试“-std=c++0x”。以防万一。我会检查你的路径。作为一个实验,我在我的Debian系统上加载了g++-4.4,并尝试在没有-stdc=c++11标志的情况下编译example.cpp,结果它在stod上阻塞了,就像你的一样。我将验证您在编译时是否使用了正确的g++编译器。如果我使用我的g++-4.7,它工作得很好。我确实在使用GCC版本,我想我是。。。有趣的是,它在同一个系统上与GCC 4.8.3配合得很好。在4.4.7安装中,通俗地说:“打断”字符串头或其他文件(例如,重命名或无意义地添加),看看它是否会影响其他文件?你的建议是什么——GCC在构建时拾取了一些不应该拾取的内容——我似乎也这么认为。gcc使用的工具(例如预处理器)中存在错误,而不仅仅是编译器。问题是我不确定在哪里可以找到这些信息,因为我已经删除了编译gcc的目录。答案可能是尝试重新编译……这个概念被松散地称为“可复制构建”或“确定性构建”。如果您打算养成构建gcc的习惯,那么您需要构建某种框架,以便每次都能够以完全相同的方式可靠地构建gcc。在最简单的情况下,这是一种预先制作的脚本形式,它获取下载的gcc源代码的原始tarball,运行tar来解压缩源代码,更改提取源代码的目录,运行configure脚本、make和make install。因此,每次这样做时,您都会得到相同的结果(续)…(续),这样在构建完成后,您就有了一个可安装的包,并且可以毫不犹豫地将包含提取源代码的目录吹走。不再需要了。如果需要创建另一个构建,只需运行脚本即可
// stod example from http://www.cplusplus.com/reference/string/stod/
#include <iostream>   // std::cout
#include <string>     // std::string, std::stod

int main ()
{
  std::string orbits ("365.24 29.53");
  std::string::size_type sz;     // alias of size_t

  double earth = std::stod (orbits,&sz);
  double moon = std::stod (orbits.substr(sz));
  std::cout << "The moon completes " << (earth/moon) << " orbits per Earth year.\n";
  return 0;
}
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/andyras/bin/gcc-4.9.1/libexec/gcc/x86_64-unknown-linux-gnu/4.9.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.9.1/configure --prefix=/home/andyras/bin/gcc-4.9.1 --enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.9.1 (GCC)
< # 277 "/opt/gcc-4.9.1/include/c++/4.9.1/cwchar" 3
---
> # 277 "/home/andyras/bin/gcc-4.9.1/include/c++/4.9.1/cwchar" 3
961,963c934,936
<   using std::wcstold;
<   using std::wcstoll;
<   using std::wcstoull;
---
> 
> 
>
85a86,108
> //gcc-4.9.1/include/c++/4.9.1/ext/string_conversions.h
> //gcc-4.9.1/include/c++/4.9.1/cstdlib
> /usr/include/stdlib.h
> /usr/include/bits/waitflags.h
> /usr/include/bits/waitstatus.h
> /usr/include/sys/types.h
> /usr/include/sys/select.h
> /usr/include/bits/select.h
> /usr/include/bits/sigset.h
> /usr/include/sys/sysmacros.h
> /usr/include/alloca.h
> //gcc-4.9.1/include/c++/4.9.1/cstdio
> /usr/include/libio.h
> /usr/include/_G_config.h
> /usr/include/bits/stdio_lim.h
> /usr/include/bits/sys_errlist.h
> //gcc-4.9.1/include/c++/4.9.1/cerrno
> /usr/include/errno.h
> /usr/include/bits/errno.h
> /usr/include/linux/errno.h
> /usr/include/asm/errno.h
> /usr/include/asm-generic/errno.h
> /usr/include/asm-generic/errno-base.h
#include <...> search starts here:
 /home/andyras/bin/gcc-4.9.1/include
 /home/andyras/bin/gcc-4.9.1/include/c++/4.9.1/
 /home/andyras/bin/gcc-4.9.1/include/c++/4.9.1/x86_64-unknown-linux-gnu/
 /home/andyras/bin/gcc-4.9.1/lib/gcc/x86_64-unknown-linux-gnu/4.9.1/include
 /usr/local/include
 /home/andyras/bin/gcc-4.9.1/lib/gcc/x86_64-unknown-linux-gnu/4.9.1/include-fixed
 /usr/include
End of search list.