Ubuntu16.04上安裝arm-linux-gcc4.4.3


一、首先下載arm-linux-gcc-4.4.3.tar.gz安裝包,安裝包地址:

http://www.cr173.com/soft/42654.html

二、解壓安裝包:

sudo tar -zxvf arm-linux-gcc-4.4.3.tar.gz -C /

注意C后面有一個空格,這樣解壓完成后的文件在:/opt/FriendlyARM/toolschain/4.4.3路徑下

三、在/usr/local目錄下新建arm目錄,並拷貝/opt/FriendlyARM/toolschain/路徑下的4.4.3到arm目錄:

cd /usr/local

sudo mkdir arm

sudo chmod 777 arm

sudo cp -r /opt/FriendlyARM/toolschain/4.4.3 /usr/local/arm

四、修改環境變量,把arm-linux-gcc添加到PATH中:

方法一:修改/etc/bash.bashrc文件,此文件只對當前用戶適用

sudo gedit /etc/bash.bashrc

在最后加上export PATH=$PATH:/usr/local/arm/4.4.3/bin

保存,退出,然后刷新環境變量使其生效:

source /root/.bashrc

方法二:修改/etc/profile文件,此文件對所有用戶適用

sudo gedit /etc/profile

在最后加上export PATH=$PATH:/usr/local/arm/4.4.3/bin

保存,退出,然后刷新環境變量使其生效:

source /etc/profile

方法三:修改/etc/environment文件

sudo gedit /etc/environment

在最后加上:/usr/local/arm/4.4.3/bin

保存,退出,然后重啟系統

五、檢查環境變量添加是否正確:

echo $PATH

如果可以顯示/usr/local/arm/4.4.3/bin,那么環境變量添加成功

六、檢查arm-linux-gcc是否安裝正確:

arm-linux-gcc -v

Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /opt/FriendlyARM/mini2440/build-toolschain/working/src/gcc-4.4.3/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/FriendlyARM/toolschain/4.4.3 --with-sysroot=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t --with-float=soft --with-pkgversion=ctng-1.6.1 --disable-sjlj-exceptions --enable-__cxa_atexit --with-gmp=/opt/FriendlyARM/toolschain/4.4.3 --with-mpfr=/opt/FriendlyARM/toolschain/4.4.3 --with-ppl=/opt/FriendlyARM/toolschain/4.4.3 --with-cloog=/opt/FriendlyARM/toolschain/4.4.3 --with-mpc=/opt/FriendlyARM/toolschain/4.4.3 --with-local-prefix=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.4.3 (ctng-1.6.1)

顯示已經安裝成功。

七、編寫測試程序,用arm-linux-gcc編譯:

建立一個空文檔,編寫以下代碼,並保存為test.c:

#include <stdio.h>

void main(void)

{

  printf("%s","Hello World!\n");

}

輸入以下命令:

arm-linux-gcc -o Hello test.c

編譯完成后會生成Hello可執行文件,輸入以下命令可以查看生成的文件信息:

readelf -h Hello

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x8334
  Start of program headers:          52 (bytes into file)
  Start of section headers:          4464 (bytes into file)
  Flags:                             0x5000002, Version5 EABI, <unknown>
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         10
  Size of section headers:           40 (bytes)
  Number of section headers:         30
  Section header string table index: 27

可以看到可執行文件的平台為ARM平台。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM