EasyArm-i.mx280a开发板入门-helloworld编译(WSL+ubuntu20.04)

1.先下载httpserver_2.3.282.1395216160软件,在windows系统上搭建一个http服务器。

网络配置:

wsl Linux  172.27.10.2 255.255.255.0

windows wsl虚拟网卡  172.27.0.1 255.255.240.0

windows有线网卡  192.168.0.233 255.255.255.0

开发板网卡:192.168.0.100 255.255.255.0

wsl linux编译结果通过挂载windows的D:盘发送文件到web服务器

开发板通过windows web服务器获取编译结果。

2.在d:盘新建一个文件夹“imx280a_exe_folder”用于存放编译结果,以便开发板便于下载。

3.打开httpserver_2.3.282.1395216160界面,将“imx280a_exe_folder”拖进httpserver的“/”

文件夹拖入后

4.编辑代码:

hello.c文件:

#include <stdio.h>

int main() {
   printf("helloworld! i am on system's userside!\n");
    return 0;
}

Makefile文件:

#CROSS_COMPILE是环境变量,是交叉编译工具的前缀,隐式声明编译器
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++

#显示声明编译器
#CC = arm-fsl-linux-gnueabi-gcc
#CXX = arm-fsl-linux-gnueabi-g++
CFLAGS = -Wall -g
CXXFLAGS = -Wall -g

# 编译 main 可执行程序
helloworld: helloworld.o 
	$(CC) $(CFLAGS) helloworld.o  -o helloworld
helloworld.o: helloworld.c
	$(CC) $(CFLAGS) -c helloworld.c -o helloworld.o

# 伪目标, 删除所有目标文件
clean:
	rm *.o main

假设我们已经搞定了交叉编译器(参见前面的文章),运行编译器

dengxm2024@PC-202105142413:~/linuxProgDir/userside_code/helloworld$ arm-fsl-linux-gnueabi-gcc
arm-fsl-linux-gnueabi-gcc: no input files

上面说明编译器没有问题:

为了和编译内核时的make风格一致,在Makefile我使用了CROSS_COMPILE这个环境变量,这个环境变量在编译内核时通常是指编译器的前缀,我在这儿指定编译器前缀为arm-fsl-linux-gnueabi-:

使用命令:

export CROSS_COMPILE=arm-fsl-linux-gnueabi-

显示以下环境变量:

echo $CROSS_COMPILE

dengxm2024@PC-202105142413:~/linuxProgDir/userside_code/helloworld$ echo $CROSS_COMPILE
arm-fsl-linux-gnueabi-

正常。

开始编译:

dengxm2024@PC-202105142413:~/linuxProgDir/userside_code/helloworld$ make
arm-fsl-linux-gnueabi-gcc -Wall -g -c helloworld.c -o helloworld.o
arm-fsl-linux-gnueabi-gcc -Wall -g helloworld.o  -o helloworld

文件夹下面生成

dengxm2024@PC-202105142413:~/linuxProgDir/userside_code/helloworld$ ls
Makefile  helloworld  helloworld.c  helloworld.o

复制helloworld到web服务器

 cp helloworld /mnt/d/imx280a_exe_folder/

打开服务器软件界面,可以看到helloworld文件

选择浏览

可以看到helloworld文件已经在web服务器上面可以看到了。

转到开发板的终端:

root@EasyARM-iMX28x ~# cd ~
root@EasyARM-iMX28x ~# ls
bcmdhd.ko          gpio_driver.ko     qt_hellow          usb_storage_up
beep.ko            hello              qt_hellow_zh
beep_test          i2c_ds2460_test    start_qt
g_file_storage.ko  lradc.ko           up_wifi_module
root@EasyARM-iMX28x ~# wget http://192.168.0.233:443/imx280a_exe_folder/hellowor
ld
Connecting to 192.168.0.233:443 (192.168.0.233:443)
helloworld           100% |*******************************|  8961   0:00:00 ETA

添加可执行属性:

root@EasyARM-iMX28x ~# chmod +x helloworld 

执行编译结果:
root@EasyARM-iMX28x ~# ./helloworld 
helloworld! i am on system's userside!

成功运行!

以上代码是我们在linux系统的用户侧做开发的简单测试!在后面的章节,我会讲述在linux系统的内核侧做开发。

  • 22
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值