Ubuntu安裝交叉工具鏈

來源:互聯網
上載者:User

 

一、下載工具鏈,並解壓到根目錄

  (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!
      #

         

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.