-O1 / 2/3与-std = c ++ 1y / 11/98 - 如果< cmath>是包含我得到错误:'_hypot'没有在此范围中声明 [英] -O1/2/3 with -std=c++1y/11/98 - If <cmath> is included i'm getting error: '_hypot' was not declared in this scope

查看:569
本文介绍了-O1 / 2/3与-std = c ++ 1y / 11/98 - 如果< cmath>是包含我得到错误:'_hypot'没有在此范围中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新MinGW使用 mingw-get-setup ,我无法建立包含< cmath> code> -std = c ++ 1y 时,使用大于 -O0 (我也试过 c ++ 11 c ++ 98 )我得到这样的错误: / p>

I've just updated MinGW using mingw-get-setup and i'm unable to build anyting that contains <cmath> header if I use anything larger than -O0 with -std=c++1y. (I also tried c++11 and c++98) I'm getting errors like this one:

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的版本bugged?

Is something wrong on my side?
Or version at mingw repo is bugged? And if so, is there any quick fix for this header?

推荐答案

为了避免任何进一步的猜测,以及严重的错误建议,如使用 #if 0 ,让我从MinGW项目贡献者的角度给出权威的答案。

To avoid any further speculation, and downright bad suggestions such as using #if 0, let me give an authoritative answer, from the perspective of a MinGW project contributor.

是, include / math.h 的MinGW.org实现确实在其内联实现中有一个错误 hypotf(float,float);编译C ++时会触发错误,包括受影响的标题(因为它包含 cmath ),任何编译器选项,指定要定义的code> __ STRICT_ANSI __ (如 -std = c ... OP)。合适的解决方案是封闭 math.h 文件的一部分, #if 0 或其他,但是要更正 hypotf(float,float)的破坏的内联实现;只需从内联引用 _hypot(float,float)中删除​​假的前导下划线,其中的返回值强制转换为float返回类型就足够了。

Yes, the MinGW.org implementation of include/math.h does have a bug in its inline implementation of hypotf (float, float); the bug is triggered when compiling C++, with the affected header included (as it is when cmath is included), and any compiler option which causes __STRICT_ANSI__ to become defined is specified, (as is the case for those -std=c... options noted by the OP). The appropriate solution is not to occlude part of the math.h file, with #if 0 or otherwise, but to correct the broken inline implementation of hypotf (float, float); simply removing the spurious leading underscore from the inline reference to _hypot (float, float), where its return value is cast to the float return type should suffice.

或者,用 -std = gnu ... 替换 -std = c ... 在编译器选项应该绕过bug,并可能提供一个合适的解决方法。

Alternatively, substituting an equivalent -std=gnu... for -std=c... in the compiler options should circumvent the bug, and may offer a suitable workaround.

FWIW,我不完全满意MinGW.org的当前实现 hypotl(long double,long double) either;纠正这两个问题是我下一个版本的MinGW运行时打印列表,但ATM,我没有时间专心准备这个。

FWIW, I'm not entirely happy with MinGW.org's current implementation of hypotl (long double, long double) either; correcting both issues is on my punch list for the next release of the MinGW runtime, but ATM, I have little time to devote to preparing this.

这篇关于-O1 / 2/3与-std = c ++ 1y / 11/98 - 如果&lt; cmath&gt;是包含我得到错误:'_hypot'没有在此范围中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆