OpenWrt: Add Hello World Application
This document describes how to create, compile, package, and install a minimal “Hello World” application inside OpenWrt. The workflow matches the OpenWrt buildroot package model, including directory layout, build phases, Makefile definitions, menuconfig selection, package compilation, installation, and runtime verification.
In this section, you are going to learn
How to create a new application package inside OpenWrt buildroot?
How OpenWrt prepares, compiles, and installs application binaries using its cross‑toolchain?
How to select the application in menuconfig and build only the package?
How to install the generated package inside a QEMU-based OpenWrt environment?
Topics in this section,
Create a new package directory inside the OpenWrt buildroot:
~/openwrt-build/openwrt/
Run:
mkdir -p package/helloworld
OpenWrt will detect this folder automatically during menuconfig and
package builds.
Every OpenWrt package lives under
package/<name>/.The package name becomes the IPK identifier.
OpenWrt buildroot is Makefile-driven and automatically discovers packages placed under the
package/hierarchy.
Create the Makefile:
package/helloworld/Makefile
Contents:
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:=Hello World Program
endef
define Package/helloworld/description
A simple hello world application for OpenWrt testing.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Package/helloworld/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin/
endef
$(eval $(call BuildPackage,helloworld))
PKG_BUILD_DIRis where OpenWrt compiles the program using its cross‑compiler.Build/Preparecopies source files to the isolated build directory.Package/helloworld/installdescribes installation into the OpenWrt rootfs.BuildPackageregisters and integrates the package with OpenWrt’s package system.
Create the source directory:
mkdir -p package/helloworld/src
Create the file:
package/helloworld/src/helloworld.c
Contents:
#include <stdio.h>
int main() {
printf("Hello from OpenWrt!\n");
return 0;
}
OpenWrt compiles using
TARGET_CCtargeting your architecture (e.g., x86_64).Compiled output becomes
$(PKG_BUILD_DIR)/helloworld.Applications typically install into
/usr/binor/usr/sbin.
OpenWrt requires explicitly selecting the package:
make menuconfig
Navigate:
Utilities --->
<M> helloworld
Save and exit.
<M>marks the package as a module, generating a standalone IPK.Avoids rebuilding a full firmware image.
Regenerates .config, integrating the package into the build pipeline.
Build the package without rebuilding the entire firmware:
make package/helloworld/{clean,compile} V=s
Output package appears under:
bin/packages/x86_64/base/helloworld*.apk
cleanwipes previous build artifacts.compileruns Prepare, Compile, Install, and package creation.Output directories vary per architecture.
Copy the built package into a running OpenWrt VM:
scp -P 2223 bin/packages/x86_64/base/helloworld*.apk root@127.0.0.1:/tmp/
Install it inside OpenWrt:
apk add --allow-untrusted /tmp/helloworld*.apk
--allow-untrustedbypasses signature verification (normal for test packages).apkextracts files exactly per the Makefile install section.Binary is installed under
/usr/bin/helloworld.
Execute the installed program:
helloworld
Expected Output:
Hello from OpenWrt!
Confirms successful compile + install.
Verifies correct OpenWrt toolchain and rootfs integration.