在 armhf 中没有实现 __fpclassify

no implementation of __fpclassify in armhf

我正在使用 ARM 的 10.3-2021.07 GCC toolchain (specifically this file uncompressed into ARMGCC). I'm also using the latest Raspberry OS image 作为 sysroot 交叉编译 Raspberry Pi 4B(循环安装到 RPISYSROOT)。主机是 Windows 主机上的 Ubuntu Xenial VM。

使用此编译行时(为便于阅读而编辑,CFLAGS 受 Pi 的 /proc/cpuinfogentoo and GNU 启发):

${ARMGCC}/bin/arm-none-linux-gnueabihf-g++ -std=c++11 \
-v -w -fexceptions -fpermissive --sysroot=$RPISYSROOT \
-pipe -mcpu=cortex-a72 -mfpu=neon-vfpv4 -mfloat-abi=hard -g \
-I . -I .. -I libA/include -I libB/include \
-I ${ARMGCC}/arm-none-linux-gnueabihf/libc/usr/include \
-I ${RPISYSROOT}/usr/include/arm-linux-gnueabihf \
-c file.cpp -o obj/debug/file.o

我收到以下错误:

$ARMGCC/arm-none-linux-gnueabihf/libc/usr/include/bits/mathcalls-helper-functions.h:20:24: error: ‘__fpclassify’ has not been declared
   20 | __MATHDECL_ALIAS (int, __fpclassify,, (_Mdouble_ __value), fpclassify)
      |                        ^~~~~~~~~~~~

我在 ARMGCCRPISYSROOT 和 Raspberry Pi 的 tools git 仓库中看到了 __fpclassify 的使用,它们似乎是相同文件的所有迭代:

usr/include/math.h
usr/include/bits/mathcalls-helper-functions.h

(路径可能略有不同)。但是,其中 none 提供了 __fpclassify 的声明或实现。这似乎来自 libm,我认为它已经成为 libc 的一部分一段时间了。我已经将 libc 安装到 RPISYSROOT
我发现的唯一实现来自 uCLibc,但我认为混合 libc 实现不是一个好主意。

此外,由于 Raspberry Pi 是 armhf,我应该看到这些错误吗?

这里的问题是混合了两组 headers,即构建链 (ARMGCC) 和指定系统根 (RPISYSROOT) 的两组。特别是,假设 file.cpp 看起来像:

#include <cmath>

void function(void) {}

您的编译命令将执行以下嵌套包含:

  • ${ARMGCC}/arm-none-linux-gnueabihf/include/c++/10.3.1/cmath
  • ${RPISYSROOT}/usr/include/math.h
  • ${ARMGCC}/arm-none-linux-gnueabihf/libc/usr/include/bits/mathcalls-helper-functions.h

您收到的特定错误(提到 __fpclassify)有点误导,因为此时最相关的未定义是 __MATHDECL_ALIAS function-like 宏,它已定义在 ${ARMGCC}/arm-none-linux-gnueabihf/libc/usr/include/math.h.

如果您查看 RPISYSROOT 下的同一个文件,您会发现它使用 __MATHDECL_1 代替:

/* Classify given number.  */
__MATHDECL_1 (int, __fpclassify,, (_Mdouble_ __value))
     __attribute__ ((__const__));

定义在${RPISYSROOT}/usr/include/math.h.

所以您需要做的是确保包含 ${RPISYSROOT}/usr/include/arm-linux-gnueabihf/bits/mathcalls-helper-functions.h 而不是 ARMGCC 对应项,您可以通过更改编译命令中包含的顺序来实现。将您的命令缩减为最基本的命令,我们有:

${ARMGCC}/bin/arm-none-linux-gnueabihf-g++ \
  --sysroot=${RPISYSROOT} \
  -I ${ARMGCC}/arm-none-linux-gnueabihf/libc/usr/include \
  -I ${RPISYSROOT}/usr/include/arm-linux-gnueabihf \
  -c file.cpp \
  -o obj/debug/file.o

如上失败。将其更改为:

${ARMGCC}/bin/arm-none-linux-gnueabihf-g++ \
  --sysroot=${RPISYSROOT} \
  -I ${RPISYSROOT}/usr/include/arm-linux-gnueabihf \
  -I ${ARMGCC}/arm-none-linux-gnueabihf/libc/usr/include \
  -c file.cpp \
  -o obj/debug/file.o

编译成功。

事实上,对于这种情况,我们可以删除对任何 ARMGCC 包含的显式引用,如下所示:

${ARMGCC}/bin/arm-none-linux-gnueabihf-g++ \
  --sysroot=${RPISYSROOT} \
  -I ${RPISYSROOT}/usr/include/arm-linux-gnueabihf \
  -c file.cpp \
  -o obj/debug/file.o

这也编译。