【发布时间】:2015-03-11 20:57:00
【问题描述】:
我正在尝试在 cygwin 下的 Windows 7 上测试一些 C++11 代码,并且对于以 C++11 开头定义的函数(例如 std::log2 和 std::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 上工作正常。