Linux C ++ ARM-Cross-Compiler楼层功能错误?

时间:2013-07-17 14:24:26

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

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

#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)为我的覆盆子交叉编译它并将我的覆盆子上的编译文件复制以执行它,那么使用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

UPDATE2 这不仅仅是双重问题。当我尝试返回float时,我也只得到零。

1 个答案:

答案 0 :(得分:0)

Maby,交叉编译器未链接到正确的浮点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链接可以帮助你更多。