c++ Builder调用未定义函数hypot/ceil/floor/fab

C++Builder call to undefined functions hypot/ceil/floor/fabs

本文关键字:ceil floor fab hypot 函数 Builder 调用 未定义 c++      更新时间:2023-10-16

最近,在我的项目中添加了一个头文件后,我无法编译我的应用程序-我添加了空白的头文件,然后出现了奇怪的错误:

[bcc32 Error] SystemTypes.h(79): E2268 Call to undefined function 'hypot'
[bcc32 Error] SystemTypes.h(511): E2268 Call to undefined function 'ceil'
[bcc32 Error] SystemTypes.h(525): E2268 Call to undefined function 'fabs'

这些错误"不知从何而来"——我也玩过另一个空项目,它们在将调试模式更改为发布模式后出现。我怎样才能修好它们呢?我不知道他们为什么会出现。下面可以看到一个错误的完整解析器上下文:

  Full parser context
    Project3.cpp(3): #include c:program files (x86)embarcaderostudio16.0includewindowsvclvcl.h
    vcl.h(10): #include c:program files (x86)embarcaderostudio16.0includewindowsvclbasepch0.h
    basepch0.h(63): #include c:program files (x86)embarcaderostudio16.0includewindowsrtlSystem.Types.hpp
    System.Types.hpp(19): #include c:program files (x86)embarcaderostudio16.0includewindowsrtlSystemTypes.h
    SystemTypes.h(32): namespace System
    SystemTypes.h(32): namespace Types
    SystemTypes.h(33): class TSmallPoint
    SystemTypes.h(87): decision to instantiate: double TSmallPoint::Distance(const TSmallPoint &) const
    --- Resetting parser context for instantiation...
    SystemTypes.h(84): parsing: double TSmallPoint::Distance(const TSmallPoint &) const

简短的回答:正如@Flame spotter所说,#include <math.h> .

长回答:这些信息告诉你什么是错的:

SystemTypes.h(87): decision to instantiate: double TSmallPoint::Distance(const TSmallPoint &) const
--- Resetting parser context for instantiation...
SystemTypes.h(84): parsing: double TSmallPoint::Distance(const TSmallPoint &) const

编译器试图实例化TSmallPoint::Distance时遇到了一个问题。如果您查看TSmallPoint::Distance的实现,您将看到如下内容:

double Distance(const TSmallPoint& p2) const _ALWAYS_INLINE {
  return hypot(p2.x - this->x, p2.y - this->y);
} 

还有关于hypot的神秘参考,这给你带来了麻烦。事实上,SystemTypes.h引用hypot而不包括<math.h>本身是一个错误。它在我的XE2副本中是固定的(我不再有XE来检查我自己),但是你应该能够通过包括<math.h>来解决它。(如果你愿意,你甚至可以编辑SystemTypes.h并在那里添加include)

至于为什么它出现在发布版本而不是调试版本-我不确定。这是一个内联函数,内联函数在发布版本和调试版本中的处理方式通常不同,"实例化"的引用听起来可能也有一些模板实例化,这可能会使事情进一步复杂化。c++ Builder的编译器不是很符合标准,我不总是理解它是如何以及何时决定抱怨某些事情的。

你需要这个include语句:

#include <math.h>