一、配置环境变量
mkdir /etc/local/arm/
tar -xvf arm-linux-4.3.2.tar.gz -C /etc/local/arm/
vim /etc/profile
放到最后面
export PATH=/usr/local/arm/4.3.1/bin:$PATH
重启系统 reboot
二、编译内核及驱动模块
进到linux源码中,打开顶层Makefile
vim Makefike
配置
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
为:
CROSS_COMPILE ?=/usr/local/arm/4.3.1/bin/arm-linux-
make ARCH=arm
三、遇到的问题
我们在交叉编译的时候可能会遇到下面两个问题,
1、
cc1: error: unrecognized command line option "-m64"
cc1: error: unrecognized command line option "-mno-red-zone"
cc1: error: unrecognized command line option "-mcmodel=kernel"
cc1: error: unrecognized command line option "-maccumulate-outgoing-args"
cc1: error: unrecognized command line option "-mno-sse"
cc1: error: unrecognized command line option "-mno-mmx"
cc1: error: unrecognized command line option "-mno-sse2"
cc1: error: unrecognized command line option "-mno-3dnow"
cc1: error: unrecognized command line option "-mno-red-zone"
cc1: error: unrecognized command line option "-mcmodel=kernel"
cc1: error: unrecognized command line option "-maccumulate-outgoing-args"
cc1: error: unrecognized command line option "-mno-sse"
cc1: error: unrecognized command line option "-mno-mmx"
cc1: error: unrecognized command line option "-mno-sse2"
cc1: error: unrecognized command line option "-mno-3dnow"
解决办法:
因为这是交叉编译,需要指定机器类型
export ARCH=arm
export ARCH=arm
2、
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
/home/aa/Desktop/learn/completion/completion/complete.o: could not read symbols: File in wrong format
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
ld: /home/aa/Desktop/learn/completion/completion/complete.o: Relocations in generic ELF (EM: 40)
/home/aa/Desktop/learn/completion/completion/complete.o: could not read symbols: File in wrong format
出现这个问题说明gcc是arm的了,但是ld还是pc的
我用
export PATH=/usr/local/arm-linux-gcc4.1.1/bin:$PATH
好像仍然不行,必须使用:
export CROSS_COMPILE=/usr/local/arm-linux-gcc4.1.1/bin/arm-linux-
我用
export PATH=/usr/local/arm-linux-gcc4.1.1/bin:$PATH
好像仍然不行,必须使用:
export CROSS_COMPILE=/usr/local/arm-linux-gcc4.1.1/bin/arm-linux-
总结:(必要的变量配置)
export ARCH=arm
export CROSS_COMPILE=arm-linux-
make ARCH=arm
export ARCH=arm
export CROSS_COMPILE=arm-linux-
make ARCH=arm