[英]-O1/2/3 with -std=c++1y/11/98 - If <cmath> is included i'm getting error: '_hypot' was not declared in this scope
我刚刚使用mingw-get-setup
更新了MinGW,如果我使用大于-O0
且-std=c++1y
任何东西,我就无法构建包含<cmath>
标头的任何东西。 (我也尝试过c++11
和c++98
)我遇到了这样的错误:
g++.exe -pedantic-errors -pedantic -Wextra -Wall -std=c++1y -O3 -c Z:\Projects\C++\L6\src\events.cpp -o obj\src\events.o
In file included from z:\lander\mingw\lib\gcc\mingw32\4.8.1\include\c++\cmath:44:0,
from Z:\Projects\C++\L6\src\utils.h:4,
from Z:\Projects\C++\L6\src\events.cpp:10:
z:\lander\mingw\include\math.h: In function 'float hypotf(float, float)':
z:\lander\mingw\include\math.h:635:30: error: '_hypot' was not declared in this scope
{ return (float)(_hypot (x, y)); }
我这边有什么不对劲吗?
或mingw repo的版本被窃听? 如果是这样,这个标题有什么快速解决方法吗?
为了避免任何进一步的推测,以及使用#if 0
等彻头彻尾的糟糕建议,让我从MinGW项目贡献者的角度给出一个权威的答案。
是的, include/math.h
的MinGW.org实现在其内联实现hypotf (float, float)
确实存在错误; 编译C ++时会触发错误,包含受影响的标头(因为包含cmath
时), 并且指定了导致__STRICT_ANSI__
定义的任何编译器选项(对于那些-std=c...
OP指出的备选方案。 适当的解决方案不是用#if 0
或其他方式遮挡math.h
文件的一部分,而是纠正hypotf (float, float)
的破坏内联实现hypotf (float, float)
; 简单地从内联引用_hypot (float, float)
删除虚假的前导下划线,其中返回值被_hypot (float, float)
转换为float返回类型就足够了。
或者,在编译器选项中替换等效的-std=gnu...
for -std=c...
应绕过该错误,并可能提供合适的解决方法。
FWIW,我对MinGW.org目前实施的hypotl (long double, long double)
也不是很满意; 纠正这两个问题是我的MinGW运行时的下一个版本的打卡列表,但ATM,我几乎没有时间专门准备这个。
更新
当前版本的MinGW.org运行时库(目前是mingwrt-3.22.4,但自3.22版本以来已修复)中不再出现此错误。 如果您使用的是旧版本(包括任何 严重损坏的 4.x版本),则应升级。
MinGW使用gcc和Microsoft运行时库。 微软的实现支持C90,但它对更高版本的C标准(C99和C11)的支持非常差。
的hypot
功能(连同hypotf
和hypotl
在C99中加入)。
如果您使用调用hypot
的程序收到此错误,例如:
#include <cmath>
int main() {
std::cout << std::hypot(3.0, 4.0)) << '\n';
}
那么它只是Microsoft运行时库的限制,因此也是MinGW的限制。 如果它出现在任何具有#include <cmath>
程序中,那么它就是MinGW中的一个错误,可能是一个配置错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.