如果工具链未知,则编译嵌入式系统的C程序

时间:2014-01-31 23:32:45

标签: gcc embedded arm cross-compiling eabi

我有一个C程序,我想在(旧)自定义嵌入式平台上进行基准测试。问题是我只有硬件而不是工具链来编译这个平台的程序。 CPU是Atmel AT91SAM9260(ARM),运行嵌入式Linux,我可以完全访问它。 我从嵌入式系统下载了一个程序,并使用'readelf -h ...'分析其格式:

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            ARM
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x8520
  Start of program headers:          52 (bytes into file)
  Start of section headers:          3772 (bytes into file)
  Flags:                             0x602, has entry point, GNU EABI, software FP, VFP
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         6
  Size of section headers:           40 (bytes)
  Number of section headers:         25
  Section header string table index: 24

然后我写了以下测试程序:

#include <stdio.h>

int main() {
  printf("Hello World!\n");
  return(0);
}

如果我在Ubuntu 12.04(arm-linux-gnueabi-gcc test.c -o test)中使用标准ARM交叉编译器,则选择了错误的EABI(Version5 EABI而不是GNU EABI)并且它不运行在嵌入式系统上(访问权限等是正确的)。

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:               0x8881
  Start of program headers:          52 (bytes into file)
  Start of section headers:          372148 (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:         7
  Size of section headers:           40 (bytes)
  Number of section headers:         30
  Section header string table index: 27

如果我使用像Sourcery CodeBench这样的裸机编译器,我会收到类似“未定义的引用...”的错误。这很清楚,因为缺少stdlib。我试图通过将所有lib文件从嵌入平台复制到主机来解决它,并使用“./arm-none-eabi-gcc test.c -o test -static -lc -L ./lib”进行编译。我仍然得到(相同的)未定义的引用错误。

如果工具链未知,为嵌入式系统编译C程序的最佳做法是什么?

0 个答案:

没有答案