我的第一个openwrt的“hello_world”应用程序hello_world.ipk

分享记录下去年调试 openwrt 项目的方法,openwrt 的第一个 hello_world 应用程序 hello_world.ipk,需要以下几个步骤:
1.在 ./package 目录下新建 hello_world 目录
2.在 ./package/hello_world /目录下创建 Makefile 和 "src" 目录
3.在 ./package/hello_world/src/ 目录下添加 hello_world.c 和 Makefile

# ll ./package/hello_world/
# ./package/hello_world/Makefile
# ./package/hello_world/src/hello_world.c
# ./package/hello_world/src/Makefile

# ./package/hello_world/Makefile

include $(TOPDIR)/rules.mk
 
PKG_NAME:=hello_world
PKG_VERSION:=1.0
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)
 
include $(INCLUDE_DIR)/package.mk
 
define Package/hello_world
	SECTION:=base
	CATEGORY:=Utilities
	TITLE:=Hello world -prints a hello world message
endef
 
define Package/hello_world/description
	If you can't figure out what this program does, you're probably
	brain-dead and need immediate medical attention.
endef
 
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
 
define Package/hello_world/install
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello_world $(1)/bin/
endef
 
$(eval $(call BuildPackage,hello_world))

# ./package/hello_world/src/Makefile

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

# ./package/hello_world/src/hello_world.c

#include <stdio.h>
 
int main(char argc,char *argv[])
{
	int i = 0;
	while(1)
	{
		printf("Hello world!!!%d\n",i);//打印内容
		i++;
		
		if(i>10) i=0;
		
		sleep(1);
		
	}
	
	return 0;
}

未完,待续......

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

__Benco

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值