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

编程入门 行业动态 更新时间:2024-10-27 03:42:29

A40i使用笔记:交叉编译*.c文件(<a href=https://www.elefans.com/category/jswz/34/1770606.html style=可在开发板运行)"/>

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_led
DEST_DIR      ?=_install
CC            ?=arm-linux-gcc
build:@$(CC) -o $(TARGET) kbqTest_led.c
hold:@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;
}

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

缺点:无

四、结语

不想说话

更多推荐

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

本文发布于:2023-06-29 00:32:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/936302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可在   开发板   文件   笔记   A40i

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!