我已经为 Raspberry PI 构建了 GCC 7.2.0,并使用前缀安装了它/usr/local/gcc-7.2.0
(使用本教程)。每当我尝试编译包含 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__));
^