【问题标题】:Error building Boost 1.49.0 with GCC 4.7.0使用 GCC 4.7.0 构建 Boost 1.49.0 时出错
【发布时间】:2012-05-26 11:51:20
【问题描述】:

我正在尝试使用 GCC 4.7.0 (MinGW) 构建 Boost 1.49.0。我不断收到以下错误消息数十次:

c:\tools\mingw\bin../lib/gcc/i686-pc-mingw32/4.7.0/../../../../include/c++/4.7.0/cmath: 1096:11:错误:'::hypot' 尚未声明

cmath 的第 1096 行包含

using ::hypot;

cmath 包括math.h,它将hypot 函数声明为

extern double __cdecl hypot (double, double); /* in libmoldname.a */

在这两个文件中,在上面引用的文件之后的几行是hypotl 函数的相同语句(除了类型是long double 而不是double),而且看起来很开心。

知道为什么我会收到此错误吗?

【问题讨论】:

    标签: c++ boost mingw


    【解决方案1】:

    @Praetorian 的回答正确识别了问题。 另一方面,Python 标头在技术上意味着排在任何其他标头之前。 此外,有时接受的解决方案在构建系统中不起作用或不方便,因此我想出了一个替代解决方案。 将以下标志添加到对 g++ 的调用中:

    -D_hypot=hypot
    

    这使得 Python 头文件中的有害宏变为空操作,编译错误消失。

    【讨论】:

    • 在构建 OpenCV 时为我工作,而“-include cmath”没有。
    【解决方案2】:

    this forum post 中找到答案。似乎 pyconfig.h 有以下几行:

    #if defined(__GNUC__) && defined(_WIN32)
    // ...
    #define hypot _hypot
    // ...
    #endif /* GNUC */
    

    但是 MinGW 包含的 cmath 期望函数命名为 hypot 而不是 _hypot,这会导致编译错误。

    修复是在我的 bjam 命令行的 cxxflags 选项中包含以下内容

    bjam ... cxxflags="-include cmath "
    

    这表明 g++ 应该在每个源文件的开头包含 cmath 标头。

    【讨论】:

    • 谢谢,成功了!
    【解决方案3】:

    据我所知,在使用 MingW 编译、使用 -std=c++0xx 并在 cmath 之前包含 Python.h 时会发生这种情况。并注意 cmath 包含在相当多的其他头文件中...... 请注意,该问题不是特定于 Boost 的。复杂的事实是,在我的标准 MingW - Visual Studio 交叉编译设置中,Visual Studio 2010 需要在调试模式下在许多其他标准包含文件之前包含 Python.h。 解决方案是首先包含 cmath,然后是 Python.h,因此您会得到如下代码:

    #include <cmath>
    #include <Python.h>
    #include < other standard headers >
    

    【讨论】:

      【解决方案4】:

      @Praetorian 正确识别了问题。

      在我的情况下,它只出现在一个文件中。所以我只是添加

      #define _hypot hypot#include &lt;Python.h&gt; 之前

      并且有效。

      希望这能有所启发。

      【讨论】:

        【解决方案5】:

        尝试查看预处理单元。我猜你会找到类似“#undef hypot”的内容。

        【讨论】:

          【解决方案6】:

          当我在链接器中添加以下路径时,我可以解决代码块中的这个错误

          C:\Python36-32\libs 
          

          并将两个库放在链接库上:libpython36.apython36.lib

          【讨论】:

            【解决方案7】:

            添加这一行

            #define _hypot hypot
            

            在您的Python.h 文件的第一个,它存储在您的python 安装目录中。像C:\Python27\include 这样的地方。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2021-03-28
              • 1970-01-01
              • 2011-07-15
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2020-03-25
              • 1970-01-01
              相关资源
              最近更新 更多