添加環境變數arm-linux-gcc__linux

來源:互聯網
上載者:User

1.下載交叉編譯器
ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/
選擇cross-3.2.tar.bz2或cross-3.2.tar.gz(此處我選cross-3.2.tar.gz)

arm-linux-gcc-3.4.1.tar.bz2
http://www.handhelds.org/download/projects/toolchain/arm-linux-gcc-3.4.1.tar.bz2

2.解包安裝
將cross-3.2.tar.gz放到 /下面直接解包(因為cross-3.2.tar.gz包本身解包後的目錄結構就是/usr/local/arm,故 而不能把cross-3.2.tar.gz再放到/sur/local下面去解包)
[root@localhost /]#tar xvzf cross-3.2-tar.gz
可在/usr/local下看到arm目錄:
[root@localhost /]# cd /usr/local
[root@localhost local]# ls
arm bin etc games include lib libexec sbin share src

3.添加交叉編譯器環境變數(三種方法a,b)
a.[root@localhost local]# export PATH=$PATH:/usr/local/arm/bin 注:(此方法只在當前終端有效)
b.修改/etc/profile檔案:
   [root@localhost local]# vi /etc/profile
   在末尾添加:export PATH=$PATH:/usr/local/arm/bin
c. 修改~/.bash_profile檔案:
    [root@localhost local]# vi ~/.basn_profile
    修改:PATH=$PATH:usr/local/arm/bin

4.使新的環境變數生效。
(b)----[root@localhost local]#source /etc/profile  
或者(c)----- [root@localhost local]#source ~/.basn_profile

5.檢查是否將路徑加入PATH
[root@localhost local]# echo $PATH
若顯示的內容中有/usr/local/arm/bin,說明已經將交叉編譯器的路徑加入PATH。自此,交叉編譯環境搭建完成。

6.測試
簡單例子:
[root@localhost local]#vi hello.c
--輸入:
/*hello.c*/
#intclude <stdio.h>
int main()
{
     printf("Hello,world!/n");
     return 0;
}
--儲存退出vi
[root@localhost local]#arm-linux-gcc hello.c -o hello
[root@localhost local]# ls
arm bin etc games hello hello.c include lib libexec sbin share src
--成功產生hello檔案
[root@localhost local]# ./hello
bash: ./hello: cannot execute binary file
--提示無法執行二進位檔案
--file一下hello檔案類型
[root@localhost local]# file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.0.0, dynamically linked (usesshared libs), not stripped
--看到沒,可執行檔ARM體系檔案

7.arm-linux-gcc交叉編譯環境搭建成功。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.