【问题标题】:C++Builder call to undefined functions hypot/ceil/floor/fabsC++Builder 调用未定义函数 hypot/ceil/floor/fabs
【发布时间】:2015-08-20 15:03:09
【问题描述】:

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

[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)\embarcadero\studio\16.0\include\windows\vcl\vcl.h
    vcl.h(10): #include c:\program files (x86)\embarcadero\studio\16.0\include\windows\vcl\basepch0.h
    basepch0.h(63): #include c:\program files (x86)\embarcadero\studio\16.0\include\windows\rtl\System.Types.hpp
    System.Types.hpp(19): #include c:\program files (x86)\embarcadero\studio\16.0\include\windows\rtl\SystemTypes.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

【问题讨论】:

    标签: c++ c++builder c++builder-xe


    【解决方案1】:

    简答:@Flame spotter said#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 并在其中添加包含。)

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

    【讨论】:

      【解决方案2】:

      你需要这个包含语句:

      #include <math.h>
      

      【讨论】:

      • 我应该把它放在哪里?我没有在我的项目中的任何地方使用数学
      • @encoreleet 在全局范围内将其添加到标题的顶部。理想情况下,您应该将它添加到发生错误的 .cpp 文件的顶部。
      • c++ builder文件“SystemTypes.h”中出现错误
      • 解释为什么需要包含将有助于提高答案的质量
      • 你好,...最后,你把那个包括在哪里?它也发生在我的 systemtypes.h 中......
      猜你喜欢
      • 1970-01-01
      • 2017-02-19
      • 2016-08-29
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-24
      • 2019-05-30
      相关资源
      最近更新 更多