部署Ubuntu GCC编译器

15 篇文章 0 订阅
13 篇文章 0 订阅
准备
  • 主机平台:Ubuntu 16.04 LTS(x64)
  • 目标平台:ARM40-A5D3
  • GCC版本:gcc version 4.9.3
  • 虚拟机:VMware® Workstation 12 Pro
  • ARM-GCC编译工具链:gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi
安装VMware® Workstation 12 Pro

在这里不再提供VMware® Workstation 12 Pro的安装教程,具体操作请参考以下链接:

安装Ubuntu 16.04 LTS(x64)

在这里不再提供Ubuntu 16.04 LTS(x64)的安装教程,具体操作请参考以下链接:

安装gcc4.9.3

运行Ubuntu,启动Terminal终端工具;输入下面的指令:

$ sudo apt-get install gcc

安装结束,查看gcc版本:

$ gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v –with-pkgversion=’Ubuntu 4.9.3-13ubuntu2’ –with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs –enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ –prefix=/usr –program-suffix=-4.9 –enable-shared –enable-linker-build-id –libexecdir=/usr/lib –without-included-gettext –enable-threads=posix –with-gxx-include-dir=/usr/include/c++/4.9 –libdir=/usr/lib –enable-nls –with-sysroot=/ –enable-clocale=gnu –enable-libstdcxx-debug –enable-libstdcxx-time=yes –enable-gnu-unique-object –disable-vtable-verify –enable-plugin –with-system-zlib –disable-browser-plugin –enable-java-awt=gtk –enable-gtk-cairo –with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre –enable-java-home –with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 –with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 –with-arch-directory=amd64 –with-ecj-jar=/usr/share/java/eclipse-ecj.jar –enable-objc-gc –enable-multiarch –disable-werror –with-arch-32=i686 –with-abi=m64 –with-multilib-list=m32,m64,mx32 –enable-multilib –with-tune=generic –enable-checking=release –build=x86_64-linux-gnu –host=x86_64-linux-gnu –target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.3 (Ubuntu 4.9.3-13ubuntu2)

安装交叉编译工具链
$ sudo xz -d gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi.tar.xz
$ ls
$ sudo tar xvf gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi.tar -C /opt/
  • 编辑.bashrc文件
$ cd ~
$ vim .bashrc
  • 在.bashrc的末尾添加下面的文本
    export PATH=$PATH:/opt/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/
  • 查看ARM-GCC版本
$ arm-linux-gnueabi-gcc -v

Thread model: posix
gcc version 4.9.4 (Linaro GCC 4.9-2017.01)

Hello World
创建,编译helloworld.c,并执行。
$ vim helloworld.c
 #include <stdio.h>
 int main(void)
 {
   printf("hello world!\n");
   return 0;
 }
$ gcc -o helloworld helloworld.c
$ ls
$ ./helloworld

hello world!

交叉编译helloworld.c,生成的可执行文件必须在ARM40上才能运行。

$ arm-linux-gnueabi-gcc -o helloworld-arm helloworld.c
$ ls
$ ./helloworld-arm

bash: ./helloworld-arm: cannot execute binary file: 可执行文件格式错误

参考引用
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值