openwrt编写hello_world ipk

本文介绍如何在OpenWRT环境下搭建并构建一个简单的Hello World模块。通过创建特定目录结构及Makefile配置文件,实现模块的编译与安装过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装好交叉编译环境,在package目录建立hello_world目录,用于存放hello_world的相关Makefile文件和.c文件,hello_world目录建立src目录和Makefile文件,src目录建立hello_world.c 和 Makefile。

openwrt@qk365-openwrt:~/qsdk$ mkdir package/hello_world
openwrt@qk365-openwrt:~/qsdk$ mkdir package/hello_world/src
openwrt@qk365-openwrt:~/qsdk$ vim package/hello_world/Makefile
//编写hello_world下的Makefile文件
openwrt@qk365-openwrt:~/qsdk$vim package/hello_world/src/Makefile
//编写src下的Makefile文件
openwrt@qk365-openwrt:~/qsdk$vim package/hello_world/src/hello_world.c

hello_world目录下的Makefile

include $(TOPDIR)/rules.mk
//包含相关规则
PKG_NAME:=hello_world   //package名字
PKG_VERSION:=1.0        //package版本
PKG_RELEASE:=1          //package发布版本
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
                        //package路径
include $(INCLUDE_DIR)/package.mk

define Package/hello_world
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=Hello workd -prints a hello world message
endef

define Package/hello_world/description
    If you can't figure out what this program does,you're probaly brain-dead and need immediate medical attention.
endef

define Build/Prepare  
    echo "Here is Package/Prepare"
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Package/hello_world/install
    echo "Here is Package/install"
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/hello_world $(1)/usr/bin/
endef

$(eval $(call BuildPackage,hello_world))   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值