建立ARM(Raspberry Pi)交叉编译环境
建立交叉编译环境有几种方式:1. 单个编译,最后形成整体交叉编译环境。2.使用现成的编译工具包基于第1种的难度,我们这里只叙述第2种,有兴趣的童鞋可以Google第1种的实现。
1. 下载交叉编译工具链 http://arm9download.cncncn.com/mini2440/linux/arm-linux-gcc-4.4.3-20100728.tar.gz (感谢 友善之臂 提供了这么好的工具)
2. 在Linux上解码tar zxvf arm-linux-gcc-4.4.3-20100728.tar.gz /usr/local/arm (“/usr/local/arm” 目录用户存放工具链)
3. 设置环境变量 export PATH=$PATH:/usr/local/arm/4.4.3/bin 这种是临时做法,每次编译前必须运行一次,但是这样对于arm编译次数少的人比较合适。如果想系统启动后自动的话可以将此行加入到.bashrc 文件底部即可。
4. 验证 arm-linux-gcc --verison(下面是我的显示)
pengyu@localhost:/usr/local/arm$ arm-linux-gcc --version
.arm-none-linux-gnueabi-gcc (ctng-1.6.1) 4.4.3
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5. 测试 vi main.c
#include <stdio.h>
int main()
{
printf("Hello, Raspberry Pi!");
return 0;
}
6. arm-linux-gcc main.c -o main (生成main程序)
7. 此时编译的接入无法在宿主机,ldd main后有类似提示直接运行会类似提示
pengyu@localhost:~$ ./main
bash: ./main: cannot execute binary file
pengyu@localhost:~$ ldd main
不是动态可执行文件
8. 验证执行程序的类型 请注意“ Machine: ARM”
pengyu@localhost:~$ readelf -a main
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: REL (Relocatable file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 328 (bytes into file)
Flags: 0x5000000, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 15
Section header string table index: 12
Section Headers:
Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 00
[ 1] .text PROGBITS 00000000 000034 000028 00AX0 04
[ 2] .rel.text REL 00000000 000504 000018 08 13 14
[ 3] .data PROGBITS 00000000 00005c 000000 00WA0 01
[ 4] .bss NOBITS 00000000 00005c 000000 00WA0 01
[ 5] .rodata PROGBITS 00000000 00005c 000018 00 A0 04
[ 6] .ARM.extab PROGBITS 00000000 000074 00000c 00 A0 04
[ 7] .ARM.exidx ARM_EXIDX 00000000 000080 000008 00AL1 04
[ 8] .rel.ARM.exidx REL 00000000 00051c 000018 08 13 74
[ 9] .comment PROGBITS 00000000 000088 000019 01MS0 01
.note.GNU-stack PROGBITS 00000000 0000a1 000000 00 0 01
.ARM.attributes ARM_ATTRIBUTES00000000 0000a1 00002a 00 0 01
.shstrtab STRTAB 00000000 0000cb 00007b 00 0 01
.symtab SYMTAB 00000000 0003a0 000130 10 14164
.strtab STRTAB 00000000 0004d0 000033 00 0 01
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
There are no program headers in this file.
Relocation section '.rel.text' at offset 0x504 contains 3 entries:
Offset Info Type Sym.ValueSym. Name
0000000c0000111c R_ARM_CALL 00000000 printf
0000002000000028 R_ARM_V4BX
0000002400000502 R_ARM_ABS32 00000000 .rodata
Relocation section '.rel.ARM.exidx' at offset 0x51c contains 3 entries:
Offset Info Type Sym.ValueSym. Name
000000000000022a R_ARM_PREL31 00000000 .text
0000000000001200 R_ARM_NONE 00000000 __aeabi_unwind_cpp_pr1
000000040000092a R_ARM_PREL31 00000000 .ARM.extab
Unwind table index '.ARM.exidx' at offset 0x80 contains 1 entries:
0x0: @0x0
Compact model 1
0x9b vsp = r11
0x40 vsp = vsp - 4
0x84 0x80 pop {r11, r14}
0xb0 finish
0xb0 finish
Symbol table '.symtab' contains 19 entries:
Num: ValueSize Type Bind Vis Ndx Name
0: 00000000 0 NOTYPELOCALDEFAULTUND
1: 00000000 0 FILE LOCALDEFAULTABS main.cpp
2: 00000000 0 SECTION LOCALDEFAULT 1
3: 00000000 0 SECTION LOCALDEFAULT 3
4: 00000000 0 SECTION LOCALDEFAULT 4
5: 00000000 0 SECTION LOCALDEFAULT 5
6: 00000000 0 NOTYPELOCALDEFAULT 5 $d
7: 00000000 0 NOTYPELOCALDEFAULT 1 $a
8: 00000024 0 NOTYPELOCALDEFAULT 1 $d
9: 00000000 0 SECTION LOCALDEFAULT 6
10: 00000000 0 NOTYPELOCALDEFAULT 6 $d
11: 00000000 0 SECTION LOCALDEFAULT 7
12: 00000000 0 NOTYPELOCALDEFAULT 7 $d
13: 00000000 0 SECTION LOCALDEFAULT 10
14: 00000000 0 SECTION LOCALDEFAULT 9
15: 00000000 0 SECTION LOCALDEFAULT 11
16: 00000000 40 FUNC GLOBAL DEFAULT 1 main
17: 00000000 0 NOTYPEGLOBAL DEFAULTUND printf
18: 00000000 0 NOTYPEGLOBAL DEFAULTUND __aeabi_unwind_cpp_pr1
No version information found in this file.
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_align8_needed: Yes
Tag_ABI_align8_preserved: Yes, except leaf SP
Tag_ABI_enum_size: int
Tag_ABI_optimization_goals: Aggressive Debug
pengyu@localhost:~$
9. 大功告成,拷贝main进入SD后然后执行即可。
10.进入Raspberry Pi的编程乐园吧。。。 帮顶,感谢支持 好东西,顶一个 顶一个pengyou@localhost
回 bianbian 的帖子
bianbian:顶一个pengyou@localhost (2012-07-24 10:22) images/back.gif嘿嘿,名字嘛 只要是linux下的操作系统就行吧?我用的是ubuntu
页:
[1]