我有一个 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 交叉编译器(arm-linux-gnueabi-gcc test.c -o test),则会选择错误的 EABI(版本 5 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 这样的裸机编译器,我会收到诸如“未定义的引用...”之类的错误。这很清楚,因为缺少标准库。我试图通过将所有 lib 文件从嵌入平台复制到主机并使用“./arm-none-eabi-gcc test.c -o test -static -lc -L ./lib”编译它来解决它。我仍然得到(相同的)未定义的参考错误。
如果工具链未知,为嵌入式系统编译 C 程序的最佳实践是什么?