查看: 9251|回复: 5
收起左侧

[开发相关] 建立ARM(Raspberry Pi)交叉编译环境

2012-7-23 23:05:27 | 显示全部楼层 |阅读模式
建立交叉编译环境有几种方式:1. 单个编译,最后形成整体交叉编译环境。2.使用现成的编译工具包
基于第1种的难度,我们这里只叙述第2种,有兴趣的童鞋可以Google第1种的实现。

1. 下载交叉编译工具链 http://arm9download.cncncn.com/m ... 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:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 000028 00  AX  0   0  4
  [ 2] .rel.text         REL             00000000 000504 000018 08     13   1  4
  [ 3] .data             PROGBITS        00000000 00005c 000000 00  WA  0   0  1
  [ 4] .bss              NOBITS          00000000 00005c 000000 00  WA  0   0  1
  [ 5] .rodata           PROGBITS        00000000 00005c 000018 00   A  0   0  4
  [ 6] .ARM.extab        PROGBITS        00000000 000074 00000c 00   A  0   0  4
  [ 7] .ARM.exidx        ARM_EXIDX       00000000 000080 000008 00  AL  1   0  4
  [ 8] .rel.ARM.exidx    REL             00000000 00051c 000018 08     13   7  4
  [ 9] .comment          PROGBITS        00000000 000088 000019 01  MS  0   0  1
  [10] .note.GNU-stack   PROGBITS        00000000 0000a1 000000 00      0   0  1
  [11] .ARM.attributes   ARM_ATTRIBUTES  00000000 0000a1 00002a 00      0   0  1
  [12] .shstrtab         STRTAB          00000000 0000cb 00007b 00      0   0  1
  [13] .symtab           SYMTAB          00000000 0003a0 000130 10     14  16  4
  [14] .strtab           STRTAB          00000000 0004d0 000033 00      0   0  1
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.Value  Sym. Name
0000000c  0000111c R_ARM_CALL        00000000   printf
00000020  00000028 R_ARM_V4BX      
00000024  00000502 R_ARM_ABS32       00000000   .rodata

Relocation section '.rel.ARM.exidx' at offset 0x51c contains 3 entries:
Offset     Info    Type            Sym.Value  Sym. Name
00000000  0000022a R_ARM_PREL31      00000000   .text
00000000  00001200 R_ARM_NONE        00000000   __aeabi_unwind_cpp_pr1
00000004  0000092a 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:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS main.cpp
     2: 00000000     0 SECTION LOCAL  DEFAULT    1
     3: 00000000     0 SECTION LOCAL  DEFAULT    3
     4: 00000000     0 SECTION LOCAL  DEFAULT    4
     5: 00000000     0 SECTION LOCAL  DEFAULT    5
     6: 00000000     0 NOTYPE  LOCAL  DEFAULT    5 $d
     7: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 $a
     8: 00000024     0 NOTYPE  LOCAL  DEFAULT    1 $d
     9: 00000000     0 SECTION LOCAL  DEFAULT    6
    10: 00000000     0 NOTYPE  LOCAL  DEFAULT    6 $d
    11: 00000000     0 SECTION LOCAL  DEFAULT    7
    12: 00000000     0 NOTYPE  LOCAL  DEFAULT    7 $d
    13: 00000000     0 SECTION LOCAL  DEFAULT   10
    14: 00000000     0 SECTION LOCAL  DEFAULT    9
    15: 00000000     0 SECTION LOCAL  DEFAULT   11
    16: 00000000    40 FUNC    GLOBAL DEFAULT    1 main
    17: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND printf
    18: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __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的编程乐园吧。。。
回复

使用道具 举报

2012-7-23 23:49:22 | 显示全部楼层
帮顶,感谢支持
回复 支持 反对

使用道具 举报

2012-7-24 07:11:47 | 显示全部楼层
好东西,顶一个
回复 支持 反对

使用道具 举报

2012-7-24 10:22:31 | 显示全部楼层
顶一个pengyou@localhost
回复 支持 反对

使用道具 举报

 楼主| 2012-7-24 18:10:30 | 显示全部楼层

回 bianbian 的帖子

bianbian:顶一个pengyou@localhost (2012-07-24 10:22) 
嘿嘿,名字嘛
回复 支持 反对

使用道具 举报

2014-3-5 15:51:35 | 显示全部楼层
只要是linux下的操作系统就行吧?我用的是ubuntu
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热点推荐

关注我们,了解更多

官方微信

服务时间:10:00-16:00

13714503811

公司地址:深圳市龙岗区南湾街道东门头路8号

Copyright © 2012-2020 Powered by 树莓派论坛 2019.4  粤ICP备15075382号-1
快速回复 返回列表 返回顶部