Welcome 微信登录

首页 / 操作系统 / Linux / Ubuntu 16.04上安装arm-linux-gcc-4.4.3

Ubuntu 16.04上安装arm-linux-gcc-4.4.3一、首先下载arm-linux-gcc-4.4.3.tar.gz安装包,安装包地址:http://www.linuxidc.com/Linux/2011-05/35906.htm二、解压安装包: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/localsudo mkdir armsudo chmod 777 armsudo 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 -vUsing 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! ");}输入以下命令:arm-linux-gcc -o Hello test.c编译完成后会生成Hello可执行文件,输入以下命令可以查看生成的文件信息:readelf -h HelloELF 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平台。更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2本文永久更新链接地址