不能使用包含math.h和g ++ 7的C库(Raspberry PI)

时间:2018-01-30 04:36:25

标签: c++ raspberry-pi g++ math.h gcc7

我为Raspberry PI构建了GCC 7.2.0,并使用前缀/usr/local/gcc-7.2.0安装了它(使用this tutorial)。每当我尝试编译包含C库的源时,该库又包含math.h,我会遇到奇怪的错误。以下是一个最小的例子:

extern "C" {
#include <libavcodec/avcodec.h>
}

int main() {
    return 0;
}

注意: extern "C"是必要的,因为avcodec.h没有它。我确定这不是问题,因为我已经尝试删除它并仍然得到同样的错误。

使用/usr/local/gcc-7.2.0/bin/g++-7.2.0 main.cpp进行编译,出现以下错误:

In file included from /usr/local/include/libavutil/common.h:36:0,
                 from /usr/local/include/libavutil/avutil.h:296,
                 from /usr/local/include/libavutil/samplefmt.h:24,
                 from /usr/local/include/libavcodec/avcodec.h:31,
                 from main.cpp:4:
/usr/local/gcc-7.2.0/include/c++/7.2.0/math.h:65:12: error: ‘constexpr bool std::isinf(double)’ conflicts with a previous declaration
 using std::isinf;
            ^~~~~
In file included from /usr/include/features.h:374:0,
                 from /usr/include/errno.h:28,
                 from /usr/local/include/libavcodec/avcodec.h:30,
                 from main.cpp:4:
/usr/include/arm-linux-gnueabihf/bits/mathcalls.h:201:1: note: previous declaration ‘int isinf(double)’
 __MATHDECL_1 (int,isinf,, (_Mdouble_ __value)) __attribute__ ((__const__));
 ^
In file included from /usr/local/include/libavutil/common.h:36:0,
                 from /usr/local/include/libavutil/avutil.h:296,
                 from /usr/local/include/libavutil/samplefmt.h:24,
                 from /usr/local/include/libavcodec/avcodec.h:31,
                 from main.cpp:4:
/usr/local/gcc-7.2.0/include/c++/7.2.0/math.h:66:12: error: ‘constexpr bool std::isnan(double)’ conflicts with a previous declaration
 using std::isnan;
            ^~~~~
In file included from /usr/include/features.h:374:0,
                 from /usr/include/errno.h:28,
                 from /usr/local/include/libavcodec/avcodec.h:30,
                 from main.cpp:4:
/usr/include/arm-linux-gnueabihf/bits/mathcalls.h:234:1: note: previous declaration ‘int isnan(double)’
 __MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
 ^

1 个答案:

答案 0 :(得分:2)

您有全局命名空间冲突,因为math.h在全局命名空间中声明了C名称。

问题出在您的page_permissions__page_id版本中。在使用C ++ 11或更新版本时,有一个补丁通过有条件地定义mathcalls.hisnan来修复它。 Here is the patch for mathcalls.h