OpenWrt Forum Archive

Topic: How to create/compile helloworld program

The content of this topic has been archived on 18 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

The following is the <openwrt root directory>/feeds/packages/utils/helloworld/Makefile for my helloworld package:

include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)    
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=$(PKG_NAME)
    MAINTAINER:=Mazilo <myEmail.add>
endef

define Package/$(PKG_NAME)/description
    This is a hello world package that contains a program to only print "hello world".
endef

CONFIGURE_VARS+= \
    CC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)"

define Package/$(PKG_NAME)/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(CP) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

My helloword-1.0.0.tar.xz file contains only two files, namely Makefile and helloworld.c as shown below:

[mazilo@Mi:/opt/openwrt-svn-trunk 460%] ~ tar -Jvtf dl/helloworld-1.0.0.tar.xz
drwxr-xr-x mazilo/users      0 2013-04-26 19:01 helloworld-1.0.0/
-rw-r--r-- mazilo/users    158 2013-04-26 19:01 helloworld-1.0.0/Makefile
-rw-r--r-- mazilo/users     75 2013-04-26 18:37 helloworld-1.0.0/helloworld.c
[mazilo@Mi:/opt/openwrt-svn-trunk 461%] ~

The Makefile from the helloworld-1.0.0.tar.xz file is as follows:

helloworld: helloworld.o
        $(CC) $(LDFLAGS) helloworld.o -o helloworld

helloworld.o: helloworld.c
        $(CC) $(CFLAGS) -c helloworld.c

clean:
        rm *.o helloworld

while the helloworld.c is as follows:

#include <stdio.h>
int main(void)
{
        printf("Hello World\n");
        return 0;
}

You can create the helloworld-1.0.0.tar.xz package as follows:

  1. Create a directory called helloword-1.0.0

  2. Inside the helloworld-1.0.0 directory, create both the Makefile and helloworld.c files

  3. Use tar utility to package the helloworld-1.0.0 subdirectory, i.e. tar -Jcf helloworld-1.0.0.tar.xz helloworld-1.0.0

  4. Move the helloworld-1.0.0.tar.xz file to your OpenWRT download directory

To compile the helloworld package, do as follows:

  1. Run scripts/feeds install helloworld (suggested below by salutuj)

  2. Run make menuconfig

  3. Go to Utilities sub menu and enable helloworld package

  4. < Exit > and < Exit .> to save the changes.

  5. Now, just run make package/helloworld/compile to compile helloworld package (thanks jow for the correction)

(Last edited by mazilo on 18 Feb 2014, 05:52)

Very nice straightforward example, and useful to refer people to when the question comes up, as it regularly does.

Final step 4. should be "make package/helloworld/compile"

jow wrote:

Final step 4. should be "make package/helloworld/compile"

I edited the post to fix the missing /compile. Thank you Jow.

Could you add the following line in tutorial, before make menuconfig, please?

Run scripts/feeds install helloworld

(Last edited by salutuj on 16 Jul 2013, 01:44)

I'd love to see them include an option for gcc and the associated dev libraries needed to compile on the router itself. Now that systems are getting USB 3.0 and 256-512MB of RAM it is feasible.

You can have them installed when you install optware. Unfortunately entware which is modernised version of optware does not have them.

Very nice tutorial, but unfortunately I have problems to compile the hello-package. 

In short my steps:
I'm using the last Version of backfire (/home/OpenWRT/backfire).
- Copied the Makefile in /home/OpenWRT/backfire/feeds/packages/utils/helloworld/
- Created the helloworld.c,  Makefile and the tarfile. Compiling under Linux (Debian) is successful.
- Copied the file helloworld-1.0.0.tar.xz to /home/OpenWRT/backfire/build_dir

Failure running:    ./scripts/feeds install helloworld:

WARNING: No feed for package 'helloworld' found, maybe it's already part of the standard packages?

In make menuconfig I can't find the helloworld packages (I assume due to the failure above).

I'm not a Linux developer, but like to know how to add some simple code to OpenWRT Maybe someone can give me some support.

Thank you!
Peter

interesting....I wonder further development like clear channel selection.... too many inside tricks in the router.

I also had the same problem - No feed message and it does not show up in the Utilities section of make menuconfig as excpected.

Any assistance would be appreciated.

Steve Donegan
steve@donegan.org

Sorry, I left off that I am using kamikaze, not backfire but the failure mode is the same.

If it is not showing then your feed is might not up to date.

1. check if you dir nd Makefile is at the correct place (usually feeds/packages/helloworld directory)
2. run srcripts/feeds update -a
3. run scripts/feeds install helloworld

What is the output? If something like "Installing package... " then it must come up in the menuconfig.

(Last edited by GABIKA6 on 26 Nov 2014, 13:17)

Hi All

Some small update on this helloworld package

To fix this message :
WARNING: No feed for package 'helloworld' found, maybe it's already part of the standard packages?

You need as well to modify feeds/packages.index file and declare helloword package as part of it with a section like this :

Source-Makefile: feeds/packages/utils/helloworld/Makefile
Package: helloworld
Version: 1.0.0
Depends: +libc +SSP_SUPPORT:libssp +USE_GLIBC:librt +USE_GLIBC:libpthread
Conflicts:
Menu-Depends:
Provides:
Section: utils
Category: Utilities
Title: Hello Program
Maintainer:
Source: helloworld-1.0.0.tar.gz
License: GPL-2.0
LicenseFiles: COPYING
Type: ipkg
Description: Hello world
@@

This has fixed the problem for me.

Hope it helps.

To fix the issue:
WARNING: No feed for package 'helloworld' found, maybe it's already part of the standard packages?

My try:
add scripts/feeds update -i before scripts/feeds install helloworld

and it worked to me.

So lets say i completed all the steps above, what would i need to do to bring the package onto my OpenWRT-Raspberry Pi3?

srmeister wrote:

So lets say i completed all the steps above, what would i need to do to bring the package onto my OpenWRT-Raspberry Pi3?

You only have to copy using scp, for example:

scp yourpacket.ipk root@192.168.1.1:/tmp/

Once you are in your RaspBerry Pi3:

cd /tmp/
opkg install yourpacket.ipk

The discussion might have continued from here.