一、下載工具鏈,並解壓到根目錄
(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!
#