一种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
#

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

2420

被折叠的 条评论
为什么被折叠?



