【问题标题】:Linux C++ ARM-Cross-Compiler floor function bug?Linux C++ ARM-Cross-Compiler floor function bug?
【发布时间】:2013-07-17 14:24:25
【问题描述】:

以下示例应用程序应该设置一个整数值:

#include <iostream>
#include <math.h>

int Round(double val)
{
    return val + 0.5;
}

double Round2(double val)
{
    return floor(val + 0.5);
}

int main() {
    double val1 = 16.75;
    cout << "Round 16.75: " << Round(val1) << endl;
    cout << "Round 21.60: " << Round2(21.60) << endl;
    cout << "Round 5.50: " << Round(5.50) << endl;
    cout << "Round 5.40: " << Round2(5.40) << endl;
}

在我的台式电脑上,这两个功能都正常工作。

如果我使用 arm-gnueabi-toolchain (v4.7.2) 为我的 raspberry 交叉编译它并将编译后的文件复制到我的 raspberry 上执行它,使用 floor 函数的函数总是返回零。

如果我在我的树莓派上编译应用程序,它就可以正常工作。

这是一个错误还是我做错了什么?

更新:

arm-linux-gnueabi-readelf -h -A stamp 
    ELF Header:
      Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
      Class:                             ELF32
      Data:                              2's complement, little endian
      Version:                           1 (current)
      OS/ABI:                            UNIX - System V
      ABI Version:                       0
      Type:                              EXEC (Executable file)
      Machine:                           ARM
      Version:                           0x1
      Entry point address:               0x8908
      Start of program headers:          52 (bytes into file)
      Start of section headers:          4852 (bytes into file)
      Flags:                             0x5000002, has entry point, Version5 EABI
      Size of this header:               52 (bytes)
      Size of program headers:           32 (bytes)
      Number of program headers:         8
      Size of section headers:           40 (bytes)
      Number of section headers:         32
      Section header string table index: 29
    Attribute Section: aeabi
    File Attributes
      Tag_CPU_name: "4T"
      Tag_CPU_arch: v4T
      Tag_ARM_ISA_use: Yes
      Tag_THUMB_ISA_use: Thumb-1
      Tag_ABI_PCS_wchar_t: 4
      Tag_ABI_FP_denormal: Needed
      Tag_ABI_FP_exceptions: Needed
      Tag_ABI_FP_number_model: IEEE 754
      Tag_ABI_align_needed: 8-byte
      Tag_ABI_align_preserved: 8-byte, except leaf SP
      Tag_ABI_enum_size: int
      Tag_DIV_use: Not allowed

更新2 这不仅仅是双倍的问题。当我尝试返回 float 时,我也只得到零。

【问题讨论】:

  • 也许您禁用了浮点支持?在资源有限的系统上并不少见,因为 FP 的计算量很大。
  • Rpi-FAQ 表示wheezy 图像使用hardware floating point。所以我猜,它启用了吗?
  • 是的,那么它应该被启用。
  • 并不意味着标准 LIBRARY 有包含“有意义的代码”的 FP 库。查看生成的二进制文件。
  • 您的 PC 编译器无法识别 CPU,并已使用 ARMv4 ISA 进行编译。您的 CPU 支持 ARMv6。使用选项-mcpu=arm1176jzf-s 编译代码。在 Raspberry 设备上,编译器可以识别 cpu 并自然使用它。

标签: c++ arm raspberry-pi cross-compiling floor


【解决方案1】:

交叉编译器可能没有链接到正确的浮点 ABI 尝试使用 -mfloat-abi=hard 进行编译。见http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html

编辑:在这个帖子中,有一些关于为 raspberrypi 构建一个用于交叉编译的好工具集的更具体的信息:Cross-compilation for Raspberry Pi in GCC. Where to start? maby 那里的链接可以帮助你更多。

【讨论】:

  • 如果我尝试这个我得到以下错误:/usr/lib/gcc/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: error: /tmp/ccWZ4jKt.o uses VFP register arguments, stamp does not/usr/lib/gcc/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: failed to merge target specific data of file /tmp/ccWZ4jKt.ocollect2: error: ld returned 1 exit status
  • @baam 我添加了一个额外的链接来查找有关 raspberrypi 交叉编译的信息,希望您能在那里找到更多有用的信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多