步骤1 在开发环境上,使用tar命令对SDK.tar.gz安装包进行解压(如下示例将SDK解压到了/
home/test/目录下,您可根据需要自行指定解压目录)。
tar -zxvf SDK.tar.gz -C /home/test
步骤2 使用source命令执行aos目录下envset.sh脚本,配置aos场景下的编译工具链所在路
径。
source /home/test/SDK/aos/envset.sh
步骤3 检查LLVM编译工具链配置是否正确。
which clang
输出结果: /home/test/SDK/aos/bin/clang
步骤4 准备代码,此处示例代码如下:
ubuntu:/home/test/SDK/helloworld$ vim helloworld.c
文件中的内容,是输出一句hello world
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
步骤5 准备Makefile,示例如下:
src_file=helloworld.c
elf_file=helloworld
all:
${CC} -I ${SYSROOT}/usr/include -L ${SYSROOT}/usr/lib64 ${src_file} -o ${elf_file}
步骤6 执行make命令,编译Hello World
ubuntu:/home/test/SDK/helloworld$ export SYSROOT=/home/test/SDK/aos/sysroot/
ubuntu:/home/test/SDK/helloworld$ make
步骤7 查询编译结果,其中hellworld为编译后的可执行文件
ubuntu: /home/test/SDK/helloworld$ ls
helloworld.c helloworld Makefile
----结束