简体   繁体   English

-O1 / 2/3 with -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

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 . 我刚刚使用mingw-get-setup更新了MinGW,如果我使用大于-O0-std=c++1y任何东西,我就无法构建包含<cmath>标头的任何东西。 (I also tried c++11 and c++98 ) I'm getting errors like this one: (我也尝试过c++11c++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)); }

Is something wrong on my side? 我这边有什么不对劲吗?
Or version at mingw repo is bugged? 或mingw repo的版本被窃听? And if so, is there any quick fix for this header? 如果是这样,这个标题有什么快速解决方法吗?

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. 为了避免任何进一步的推测,以及使用#if 0等彻头彻尾的糟糕建议,让我从MinGW项目贡献者的角度给出一个权威的答案。

Yes, the MinGW.org implementation of include/math.h does have a bug in its inline implementation of hypotf (float, float) ; 是的, include/math.h的MinGW.org实现在其内联实现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). 编译C ++时会触发错误,包含受影响的标头(因为包含cmath时), 并且指定了导致__STRICT_ANSI__定义的任何编译器选项(对于那些-std=c... 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) ; 适当的解决方案不是#if 0或其他方式遮挡math.h文件的一部分,而是纠正hypotf (float, float)的破坏内联实现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. 简单地从内联引用_hypot (float, float)删除虚假的前导下划线,其中返回值被_hypot (float, float)转换为float返回类型就足够了。

Alternatively, substituting an equivalent -std=gnu... for -std=c... in the compiler options should circumvent the bug, and may offer a suitable workaround. 或者,在编译器选项中替换等效的-std=gnu... for -std=c...应绕过该错误,并可能提供合适的解决方法。

FWIW, I'm not entirely happy with MinGW.org's current implementation of hypotl (long double, long double) either; FWIW,我对MinGW.org目前实施的hypotl (long double, long double)也不是很满意; 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. 纠正这两个问题是我的MinGW运行时的下一个版本的打卡列表,但ATM,我几乎没有时间专门准备这个。

Update 更新

This bug is no longer present in the current release of the MinGW.org runtime library (currently mingwrt-3.22.4, but fixed since release 3.22). 当前版本的MinGW.org运行时库(目前是mingwrt-3.22.4,但自3.22版本以来已修复)中不再出现此错误。 If you are using anything older than this, (including any of the critically broken 4.x releases), you should upgrade. 如果您使用的是旧版本(包括任何 严重损坏的 4.x版本),则应升级。

As noted by Keith, this is a bug in the MinGW.org header. 正如Keith所说,这是MinGW.org标题中的一个错误。

As an alternative to editing the MinGW.org header, you can use MinGW-w64 , which provides everything MinGW.org provides, and a whole lot more. 作为编辑MinGW.org标题的替代方法,您可以使用MinGW-w64 ,它提供了MinGW.org提供的所有功能,还有更多功能。 For a list of differences between the runtimes, see this wiki page . 有关运行时之间差异的列表,请参阅此Wiki页面

MinGW uses gcc and the Microsoft runtime library. MinGW使用gcc和Microsoft运行时库。 Microsoft's implementation support C90, but its support for later versions of the C standard (C99 and C11) is very poor. 微软的实现支持C90,但它对更高版本的C标准(C99和C11)的支持非常差。

The hypot function (along with hypotf and hypotl ) was added in C99. hypot功能(连同hypotfhypotl在C99中加入)。

If you're getting this error with a program that calls hypot , such as: 如果您使用调用hypot的程序收到此错误,例如:

#include <cmath>
int main() {
    std::cout << std::hypot(3.0, 4.0)) << '\n';
}

then it's just a limitation of the Microsoft runtime library, and therefore of MinGW. 那么它只是Microsoft运行时库的限制,因此也是MinGW的限制。 If it occurs with any program that has #include <cmath> , then it's a bug, perhaps a configuration error, in MinGW. 如果它出现在任何具有#include <cmath>程序中,那么它就是MinGW中的一个错误,可能是一个配置错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:在此范围内未声明&#39;_hypot&#39; - error: '_hypot' was not declared in this scope Eclipse C ++ 1y(-std = c ++ 1y)与-std = c ++ 11 - Eclipse C++1y (-std=c++1y) vs -std=c++11 “错误:在尝试嵌入Python时,未在cmath中声明&#39;:: hypot&#39; - “Error: '::hypot' has not been declared” in cmath while trying to embed Python 我收到“错误:字符串未在此范围内声明” - I'm getting an "Error: string was not declared in this scope" C ++ 1y没有从std :: bind到std :: function的可行转换 - C++1y no viable conversion from std::bind to std::function 我包括了std,但是仍然出现错误,为什么呢? - I included std, but I'm still getting an error, why is that? c ++枚举范围无法使用-std = c ++ 98进行编译,但是使用-std = c ++ 11就可以了 - c++ enum scope failed to compile with -std=c++98, but ok with -std=c++11 “扩展初始化列表仅适用于 -std=c++11 或 -std=gnu++11”,我收到此错误 - “extended initializer lists only available with -std=c++11 or -std=gnu++11”, I'm Getting this error 为什么即使启用了C ++ 11并且包含了字符串,在此范围内仍未声明“ stod”? - Why is 'stod' still not declared in this scope even after C++11 is enabled and I have included string? 错误:在 lambda 参数声明中使用 &#39;auto&#39; 仅适用于 -std=c++1y 或 -std=gnu++1y [-Werror] - error: use of 'auto' in lambda parameter declaration only available with -std=c++1y or -std=gnu++1y [-Werror]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM