使用GCC 4.7.0构建Boost 1.49.0时出错

Pra*_*ian 14 c++ boost mingw

我正在尝试使用GCC 4.7.0(MinGW)构建Boost 1.49.0.我一直收到以下错误信息几十次:

C:\工具\ mingw的\ BIN ../ LIB/GCC/i686的-PC-的mingw32/4.7.0 /../../../../包括/ C++/4.7.0/CMATH:1096:11 :错误:':: hypot'尚未声明

第1096行cmath包含

using ::hypot;
Run Code Online (Sandbox Code Playgroud)

cmath包括math.h声明hypot函数的包含

extern double __cdecl hypot (double, double); /* in libmoldname.a */
Run Code Online (Sandbox Code Playgroud)

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

任何想法为什么我收到此错误?

Ian*_*anH 16

@Praetorian的答案正确地识别了问题.另一方面,Python头文件在技术上意味着要先于其他任何版本.此外,有时接受的解决方案在构建系统中不起作用或不方便,因此我提出了另一种解决方案.将以下标志添加到对g ++的调用中:

-D_hypot=hypot
Run Code Online (Sandbox Code Playgroud)

这使得Python头文件中的有害宏变为无操作,并且编译错误消失了.


Pra*_*ian 13

这个论坛帖子中找到了答案.似乎pyconfig.h有以下几行:

#if defined(__GNUC__) && defined(_WIN32)
// ...
#define hypot _hypot
// ...
#endif /* GNUC */
Run Code Online (Sandbox Code Playgroud)

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

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

bjam ... cxxflags="-include cmath "
Run Code Online (Sandbox Code Playgroud)

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