【问题标题】:cygwin support for C++11 in g++4.9.2cygwin 在 g++4.9.2 中对 C++11 的支持
【发布时间】:2015-03-11 20:57:00
【问题描述】:

我正在尝试在 cygwin 下的 Windows 7 上测试一些 C++11 代码,并且对于以 C++11 开头定义的函数(例如 std::log2std::round)出现编译错误。我正在编译 g++ -std=c++11 test.cpp,使用 gcc 4.9.2。这是一些无法编译的最小示例:

#include <cmath>
#include <iostream>

int main()
{
        auto x = std::log2(10);
        std::cout << x << std::endl;
}

错误:

g++ -std=c++11 test.cpp
test.cpp: In function ‘int main()’:
test.cpp:5:11: error: ‘log2’ is not a member of ‘std’
  auto x = std::log2(10);
           ^
test.cpp:5:11: note: suggested alternative:
In file included from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/cmath:44:0,
                 from test.cpp:1:
/usr/include/math.h:305:15: note:   ‘log2’
 extern double log2 _PARAMS((double));

这是 cygwin 的 g++ 移植中的一个已知错误吗?上面的代码适用于任何支持 C++11 的 Linux/UNIX 风格。

【问题讨论】:

  • 看起来与this相关
  • @ShafikYaghmour 哦,谢谢!我实际上是填充错误的人,不知道他们修复了它:)
  • 看起来你已经提交了错误报告,所以我有点困惑。否则我只会提供一个答案,因为它确实是固定的。或者,您可以提供一个自我回答,说明您提交了错误报告并已修复。其他人可能也会遇到这个问题。
  • 提供了答案。之前没有人报道过,其实挺惊讶的,估计很少有人用cygwin下的数值模拟。
  • 它似乎也适用于 MSYS2 的 GCC 4.9.2。在来自 vanilla MinGW/MSYS std::round 的 GCC 4.8.1 上工作正常。

标签: c++ c++11 cygwin


【解决方案1】:

问题似乎是与 cygwin 实现相关的 bug,感谢 Shafik Yaghmour 指出。

该问题现已通过&lt;cmath&gt; 的补丁修复,同样位于上面提供的链接中。

【讨论】:

  • 这个错误在 g++4.9.3 中修复了吗?谢谢
  • @sujithvm 不确定,最好查看 cygwin 错误报告系统
  • @sujithvm std::round 在我的测试中未在 4.9.3 中定义。它在 5.1.0 中定义。不确定它什么时候得到修复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-11
  • 2012-11-29
  • 2017-07-30
  • 1970-01-01
相关资源
最近更新 更多