一、下载工具链,并解压到根目录
(1)、通过samba将下载好的工具链(我这里用的是toolchains_for_s3c2410.tar.bz2)拷贝到/home目录下
解压toolchains_for_s3c2410.tar.bz2:
tar –jxvf toolchains_for_s3c2410.tar.bz2
于是生成crosstool目录,一般把它拷贝到根目录
caoyi@ubuntu:/home$ ls
caoyi crosstool kernel study toolchains_for_s3c2410.tar.bz2
caoyi@ubuntu:/home$ sudo mv crosstool/ /
(2)、获得交叉工具的绝对路径
cd crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux-gnu/bin/
pwd命令获取交叉工具链可执行文件存放的绝对路径
/crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux-gnu/bin
(3)、修改环境变量PATH的值
caoyi@ubuntu:/home$ cd ~ (当前用户目录,我的为:/home/caoyi)
caoyi@ubuntu:/home$ vim .bashrc
在最后一行中添加:
export PATH=$PATH: /crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux-gnu/bin
保存退出
或者 修改/etc/profile
执行命令:vim /etc/profile
添加:
export PATH=$PATH: /opt/crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux-gnu/bin
保存退出
最后执行:source /etc/profile
OK
执行命令:source ~/.bashrc
二、使用交叉工具链编译c代码
(1)、 在/opt/filesystem中新建一个文件夹,专门用来存放交叉编译后的可执行代码
caoyi@ubuntu:/home$ cd /rootfs/filesystem
caoyi@ubuntu:/rootfs/filesystem/$ sudo mkdir work
caoyi@ubuntu:/rootfs/filesystem/$ sudo chmod 777 -R work (注意要改变属性,否则执行编译会出现权限问题)
caoyi@ubuntu:/home$ cd /rootfs/filesystem/work/
caoyi@ubuntu:/rootfs/filesystem/work$ sudo vim hello.c
caoyi@ubuntu:/rootfs/filesystem/work$ sudo arm-linux-gnu-gcc hello.c –o hello
caoyi@ubuntu:/rootfs/filesystem/work$ ls
hello hello.c
(2)、在开发板的终端中,即putty(串口),进入/work/目录运行hello
# cd work
# ls
hello hello.c
# ./hello
Hello World!
#