openwrt编译模块demo练习

本文介绍了一种OpenWrt环境下模块编译的具体步骤,包括Makefile的配置与使用,以及常见错误的排查方法。通过实践案例,帮助读者理解并掌握如何在OpenWrt系统中构建和安装自定义模块。

一种openwrt国内使用(源码)的方案: https://blog.csdn.net/yao1500/article/details/105948229
相关内容从网络梳理,然后自己练习整理。

注意: 如果有报错,

	1:可以查看日志:OpenWrt-SDK/logs/package/helloworld/dump.txt 
	2:注意Makefile中的空格与tab键的使用。

1:实现ipk Demo的编译,理解架构:

1. 了解架构:
hlp@ubuntu:~/openwrt/openwrt-sdk-ramips-mt7621_gcc-7.4.0_musl.Linux-x86_64$ tree package/utils/
package/utils/
└── hello_world
    ├── Makefile                ===》这是模块的规则Makefile
    └── src
        ├── hello_world.c
        └── Makefile            ===》这是我们代码的规则Makefile

2 directories, 3 files
2. 代码块:
hlp@ubuntu:~/openwrt/openwrt-sdk-ramips-mt7621_gcc-7.4.0_musl.Linux-x86_64$ cat package/utils/hello_world/src/hello_world.c 

#include <stdio.h>
int main(char argc, char *argv[])
{
   
   
	int i = 1;
	while(1) {
   
   
		//1~10 循环
		printf("Hello world!!!%d\n",i); //打印内容
		if (i < 10) {
   
   
			i++;
		} else {
   
   
			i = 1;
		}
		sleep(1);// 一秒钟打印一次
	}
	return 0;
}
3. 代码块中对应的Makefile
hlp@ubuntu:~/openwrt/openwrt-sdk-ramips-mt7621_gcc-7.4.0_musl.Linux-x86_64$ cat package/utils/hello_world/src/Makefile 
all: hello_world

hello_world: hello_world.o
	$(CC) $(LDFLAGS) hello_world.o -o hello_world
	
helloworld.o: hello_world.c
	$(CC) $(CFLAGS) -c hello_world.c
	
clean:
	rm *.o hello_world

hlp@ubuntu:~/openwrt/openwrt-sdk-ramips-mt7621_gcc-7.4.0_musl.Linux-x86_64$
4. 模块对应的外层的Makefile,即hello_world模块,hello_world下层Makefile
hlp@ubuntu:~/openwrt/openwrt-sdk-ramips-mt7621_gcc-7.4.0_musl.Linux-x86_64$ cat package/utils/hello_world/Makefile 
# 引入头文件 rules.mk
include $(TOPDIR)/rules.mk

# 设置PKG_*变量
PKG_NAME:=hello_world
PKG_VERSION:=1.0
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)

# 引入头文件 package.mk
include $(INCLUDE_DIR)/package.mk

#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值