一、在openwrt系统架构,编写helloworld的应用程序。
第一步先创建目录,项目代码要放在 openwrt根目下的 package 目录中,这里源码写在了 hellworld 的 src 目录下,因为外层还有需要编写的文件。
mkdir -p ~/openwrt/package/hellworld/src
cd ~/openwrt/package/helloworld/src
然后编写 helloworld.c 和源码下的 Makefile 文件
touch helloworld.c Makefile
nano helloworld.c
nano Makefile
helloworld.c 内容如下
#include <stdio.h> |
|
int main() |
|
{
|
|
printf("hello world!\n"); |
|
return 0; |
|
} |
Makefile 包含了两个编译过程,一个清除的命令
helloworld : helloworld.o |
|
$(CC) $(LDFLAGS) helloworld.o -o helloworld |
|
helloworld.o : helloworld.c |
|
$(CC) $(CFLAGS) -c helloworld.c |
|
clean : |
|
rm *.o helloworld |
写完上面的代码后,可以简单测试一下,输入 make 编译,生成可执行文件,用 ./ 运行就可以了,使用 make clean 可以清除生成的可执行文件
make
make clean
编写配置文件
这里先进入上一层目录,即 helloworld 目录,并创建一个新的 Makefile 文件
$cd ~/openwrt/package/helloworld
$touch Makefile
接下来编写这个 Makefile 文件,内容如下
include $(TOPDIR)/rules.mk |
|
#定义相关信息 |
|
PKG_NAME:=helloworld |
|
PKG_RELEASE:=1 |
|
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) |
|
include $(INCLUDE_DIR)/package.mk |
|
define Package/helloworld |
|
SECTION:=utils |
|
CATEGORY:=Utilities |
|
TITLE:=Helloworld -- prints a snarky message |
|
endef |
|
define Package/helloworld/description |
|
It's my first package demo. |
|
endef |
|

最低0.47元/天 解锁文章
1296

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



