分类: LINUX
2014-12-12 16:53:45
1st step: 创建目录,在当前目录下,解压交叉编译工具包
#tar zxvf arm-linux-gcc-4.3.2.tgz -C /
... ...
usr/local/arm/4.3.2/lib/gcc/arm-none-linux-gnueabi/4.3.2/libgcc.a
2nd step:添加环境变量
[root@localhost 4.3.2]# vi /root/.bashr
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export PATH=$PATH:/usr/local/arm/4.3.2/bin //为所添
3rd 关闭终端,重新打开终端,输入arm-
[root@localhost 4.3.2]# arm-
arm-linux-addr2line arm-none-linux-gnueabi-addr2line
arm-linux-ar arm-none-linux-gnueabi-ar
arm-linux-as arm-none-linux-gnueabi-as
arm-linux-c++ arm-none-linux-gnueabi-c++
arm-linux-c++filt arm-none-linux-gnueabi-c++filt
arm-linux-cpp arm-none-linux-gnueabi-cpp
arm-linux-g++ arm-none-linux-gnueabi-g++
arm-linux-gcc arm-none-linux-gnueabi-gcc
arm-linux-gcc-4.3.2 arm-none
说明已经交叉环境已经建立完成。
4th 编写hello.c,然后用交叉编译
**********************************
#include
#include
main()
{
printf("hello world!\n");
}
**************************************************
[root@localhost 4-2-1]# arm-linux-gcc hello.c -o hello
5th step: 查看可执行文件格式
[root@localhost 4-2-1]# file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
附加:
反汇编
[root@localhost 4-2-1]# arm-linux-objdump -D -S hello >log
[root@localhost 4-2-1]# vi log
**************************************
hello: file format elf32-littlearm
Disassembly of section .interp:
00008134 <.interp>:
8134: 62696c2f rsbvs r6, r9, #12032 ; 0x2f00
8138: 2d646c2f stclcs 12, cr6, [r4, #-188]!
813c: 756e696c strbvc r6, [lr, #-2412]!
8140: 6f732e78 svcvs 0x00732e78
8144: Address 0x00008144 is out of bounds.
Disassembly of section .note.ABI-tag:
00008148 <.note.ABI-tag>:
8148: 00000004 .word 0x00000004
814c: 00000010 .word 0x00000010
8150: 00000001 .word 0x00000001
8154: 00554e47 .word 0x00554e47
8158: 00000000 .word 0x00000000
815c: 00000002 .word 0x00000002
8160: 00000006 .word 0x00000006
8164: 0000000e .word 0x0000000e
*******************************************************************
[root@localhost 4-2-1]# arm-linux-readelf -a hello >log
[root@localhost 4-2-1]# vi log
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: 0x82c8
Start of program headers: 52 (bytes into file)
Start of section headers: 1784 (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: 30
Section header string table index: 27
********************************************************