准备
- 主机平台:Ubuntu 16.04 LTS(x64)
- 目标平台:ARM40-A5D3
- ARM-GCC编译工具链:gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi
1、下载gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi编译工具链
2、 解压编译工具链
将编译工具链解压到主机/opt目录下。
$ sudo xz -d gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi.tar.xz
$ sudo tar xvf gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi.tar -C /opt/
3、添加环境变量
编辑主机当前账户主目录的.bashrc文件,将编译工具链的路径添加到环境变量中。
$ cd ~ #切换到当前用户的主目录下
$ vim .bashrc #编辑.bashrc文件,并在末尾添加以下文本
>>> export PATH=$PATH:/opt/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/
$ source .bashrc #使环境变量生效
$ arm-linux-gnueabi-gcc -v #查看编译器已经生效
>>> Thread model: posix
gcc version 4.9.4 (Linaro GCC 4.9-2017.01)
4、 Hello World
在主机当前账户主目录下创建helloworld.c,并使用arm-gcc工具链编译。
$ vim helloworld.c #编写helloworld.c代码,附录
$ arm-linux-gnueabi-gcc helloworld.c -o helloworld #编译helloworld.c
将编译得到的helloworld文件拷贝到ARM40-A5板上运行。
root@ARM40:# cp /media/sda1/helloworld ./ #复制helloworld到目标板当前目录下
root@ARM40:# ./helloworld #在目标板上运行helloworld
>>>hello,world! #打印hello,world
参考引用
附录
helloworld.c
#include <stdio.h>
int main(void)
{
printf("hello,world!\n");
return 0;
}