300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > A40i使用笔记:交叉编译*.c文件(可在开发板运行)

A40i使用笔记:交叉编译*.c文件(可在开发板运行)

时间:2021-06-04 20:52:13

相关推荐

A40i使用笔记:交叉编译*.c文件(可在开发板运行)

一、前言

在使用a40i时,不仅仅会用到qt环境,还会用到一些子程序,用c单独编译配置的程序,而且也具备可扩展可移植性,下面就简单介绍一下在a40i平台交叉编译方法

二、环境

ubuntu 16

vaware 12

window10

a40i交叉编译器

qt5.9

三、正文

实现交叉编译的有两种,一种是ui的qt程序,一种是不带ui的纯*.c程序

1.带ui的用qt直接选择a40i编译器进行编译(不介绍)

2.带ui的跟随系统编译

手册介绍如下:

将写好的程序放在如下目录中

然后修改下面目录中的文件,把需要跟随系统编译的写入

不想编译任何文件,文件目录就为空

3.不带ui的随着系统编译

同上,上面带ui的是随着系统一起编译,在qt5文件夹内

不带ui的是在cmd文件夹内,需要编译的文件就放在文件列表中,不编译的就不放在列表中,编译文件内容如下

kbqTest_led.c

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>char *GPIO_PATH = "/sys/class/gpio/gpio43/value";int main(int argc, char *argv[]){int fd;char *path;path = GPIO_PATH;system("echo 43 > /sys/class/gpio/export");//led6system("echo out > /sys/class/gpio/gpio43/direction");fd = open(path, O_WRONLY);if(fd<0){printf("Failed to Open gpio %s\n", path);exit(1);}while(1){write(fd, "1", 1);sleep(1);write(fd, "0", 1);sleep(1);}close(fd);return 0;}

makefile

TARGET =kbqTest_ledDEST_DIR?=_installCC ?=arm-linux-gccbuild:@$(CC) -o $(TARGET) kbqTest_led.chold:@echo "smc hold[skip]"install:@mkdir -p $(DEST_DIR)@cp $(TARGET) $(DEST_DIR)uninstall:@rm -fr $(DEST_DIR)/$(TARGET)distclean: uninstall@rm -fr $(TARGET)@rm -fr _install

在系统进行./build.sh后,可执行程序自动编译完成在文件夹中

优点:无

缺点:慢,需要编译很多系统文件 ,才顺带着编译这一个文件。

4.不带ui单独编译

单独编译某个*.c文件,和makeifle,不跟随系统统一编译

首先找到安装交叉编译器的路径,默认飞凌A40i的是

/root/workspace/allwinner/A40i/bsp/lichee/out/sun8iw11p1/linux/common/buildroot/host/opt/ext-toolchain/bin/arm-linux-gnueabihf-g++

然后执行以下程序

/root/workspace/allwinner/A40i/bsp/lichee/out/sun8iw11p1/linux/common/buildroot/host/opt/ext-toolchain/bin/arm-linux-gnueabihf-g++ kbqTest_led.c -o kbqTest_led

kbqTest_led.c

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>char *GPIO_PATH = "/sys/class/gpio/gpio43/value";int main(int argc, char *argv[]){int fd;char *path;path = GPIO_PATH;system("echo 43 > /sys/class/gpio/export");//led6system("echo out > /sys/class/gpio/gpio43/direction");fd = open(path, O_WRONLY);if(fd<0){printf("Failed to Open gpio %s\n", path);exit(1);}while(1){write(fd, "1", 1);usleep(200);write(fd, "0", 1);usleep(200);}close(fd);return 0;}

优点:快,单独编译完即可使用

缺点:无

四、结语

不想说话

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。