OpenWrt Forum Archive

Topic: Helloworld package build with OpenWRT SDK

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

Hi everyone,
I'm newbie in OpenWRT and i want to build a firmware for Buffalo WHR-HP-G300N with OpenWRT,
So I follow this tutorial http://www.ccs.neu.edu/home/noubir/Cour … torial.pdf
But i can't build package Helloworld like this tutorial
My package include:
openwrt/openwrt-sdk/package/helloworld/src/helloworld.c

#include <stdio.h>
int main()
{
printf("Hello world, Ken! \n");
return 0;
}

openwrt/openwrt-sdk/package/helloworld/src/Makefile

CC = gcc
FLAG = -Wall
helloworld:
    $(CC) $(FLAG) helloworld.c -o helloworld


openwrt/openwrt-sdk/package/helloworld/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 Program written by Ken
endef

define Package/helloworld/description
    a sample OpenWRT helloworld program
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)/hellowolrd $(1)/usr/bin
endef

$(eval $(call BuildPackage,helloworld))

when i compile with command

ken@Ken-Laptop-Ubuntu:~/openwrt/openwrt-sdk$ make package/helloworld/compile V=99

and this

#
# using defaults found in .config
#


*** End of OpenWrt configuration.
*** Execute 'make' to build the OpenWrt or try 'make help'.

make[4]: Entering directory `/home/ken/openwrt/openwrt-sdk/package/helloworld'
make[4]: Leaving directory `/home/ken/openwrt/openwrt-sdk/package/helloworld'
make[1]: Entering directory `/home/ken/openwrt/openwrt-sdk'
make[2]: Entering directory `/home/ken/openwrt/openwrt-sdk/package/helloworld'
mkdir -p /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld
cp -fpR ./src/* /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/
touch /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/.prepared_76ff201936867f921fa2d353dd9528be
(cd /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/./; if [ -x ./configure ]; then /home/ken/openwrt-sdk/staging_dir/host/bin/find /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ -name config.guess | xargs -r chmod u+w; /home/ken/openwrt-sdk/staging_dir/host/bin/find /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ -name config.guess | xargs -r -n1 cp /home/ken/openwrt/openwrt-sdk/scripts/config.guess; /home/ken/openwrt-sdk/staging_dir/host/bin/find /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ -name config.sub | xargs -r chmod u+w; /home/ken/openwrt-sdk/staging_dir/host/bin/find /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ -name config.sub | xargs -r -n1 cp /home/ken/openwrt/openwrt-sdk/scripts/config.sub; AR=-openwrt-linux-ar AS="-openwrt-linux-gcc -c  -fhonour-copts" LD=-openwrt-linux-ld NM=-openwrt-linux-nm CC="-openwrt-linux-gcc" GCC="-openwrt-linux-gcc" CXX="no" RANLIB=-openwrt-linux-ranlib STRIP=-openwrt-linux-strip OBJCOPY=-openwrt-linux-objcopy OBJDUMP=-openwrt-linux-objdump SIZE=-openwrt-linux-size CFLAGS=" -fhonour-copts " CXXFLAGS=" -fhonour-copts " CPPFLAGS="-I/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/usr/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/usr/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/include " LDFLAGS="-L/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/usr/lib -L/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/lib -L/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/usr/lib -L/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/lib "   ./configure --target=-openwrt-linux --host=-openwrt-linux --build=i686-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --disable-largefile --disable-ipv6 ; fi; )
touch /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/.configured_
CFLAGS=" -fhonour-copts  -I/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/usr/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/usr/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/include " CXXFLAGS=" -fhonour-copts  -I/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/usr/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/usr/include -I/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/include " LDFLAGS="-L/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/usr/lib -L/home/ken/openwrt/openwrt-sdk/staging_dir/target-_-/lib -L/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/usr/lib -L/home/ken/openwrt/openwrt-sdk/staging_dir/toolchain-_gcc-_-/lib " make -C /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/. AR=-openwrt-linux-ar AS="-openwrt-linux-gcc -c  -fhonour-copts" LD=-openwrt-linux-ld NM=-openwrt-linux-nm CC="-openwrt-linux-gcc" GCC="-openwrt-linux-gcc" CXX="no" RANLIB=-openwrt-linux-ranlib STRIP=-openwrt-linux-strip OBJCOPY=-openwrt-linux-objcopy OBJDUMP=-openwrt-linux-objdump SIZE=-openwrt-linux-size CROSS="-openwrt-linux-" ARCH="" ;
make[3]: Entering directory `/home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld'
make[3]: `helloworld' is up to date.
make[3]: Leaving directory `/home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld'
touch /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/.built
rm -rf /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld
mkdir -p /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL
echo "Package: helloworld" > /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL/control
echo "Version: 1" >> /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL/control
( DEPENDS=''; for depend in ; do DEPENDS=${DEPENDS:+$DEPENDS, }${depend##+}; done; echo "Depends: $DEPENDS"; echo "Provides: "; echo "Source: package/helloworld"; echo "Section: utils"; echo "Status: unknown ok not-installed"; echo "Essential: no"; echo "Priority: optional"; echo "Maintainer: OpenWrt Developers Team <openwrt-devel@openwrt.org>"; echo "Architecture: "; echo "Installed-Size: 0"; echo -n "Description: "; getvar V_Package_helloworld_description | sed -e 's,^[[:space:]]*, ,g'; ) >> /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL/control
chmod 644 /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL/control
(cd /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL;  )
install -d -m0755 /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/usr/bin
install -m0755 /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/hellowolrd /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/usr/bin
install: cannot stat '/home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/hellowolrd': No such file or directory
make[2]: *** [/home/ken/openwrt/openwrt-sdk/bin//packages/helloworld_1_.ipk] Error 1
make[2]: Leaving directory `/home/ken/openwrt/openwrt-sdk/package/helloworld'
make[1]: *** [package/helloworld/compile] Error 2
make[1]: Leaving directory `/home/ken/openwrt/openwrt-sdk'
make: *** [package/helloworld/compile] Error 2

i dont know why "install: cannot stat"
Any suggestion for this case ?
Thanks for reading

(Last edited by hoangvu23108 on 6 Nov 2014, 14:45)

In your Makefile, change:
$(INSTALL_BIN) $(PKG_BUILD_DIR)/hellowolrd $(1)/usr/bin
by
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin

KHAN85 wrote:

In your Makefile, change:
$(INSTALL_BIN) $(PKG_BUILD_DIR)/hellowolrd $(1)/usr/bin
by
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin

sr change what KHAN85, i cant see difference in 2 command?

You wrote "woLRd" instead "woRLd", that's the error.

KHAN85 wrote:

You wrote "woLRd" instead "woRLd", that's the error.

oh ok, i dont see i wrote wrong that "world"
thanks you so much i will try now

KHAN85 wrote:

You wrote "woLRd" instead "woRLd", that's the error.

LOL ... looking for such a typo is like asking someone to search for a needle in a haystack with bare hands. To avoid that kind of typo, I prefer to use a variable to represent an entity that gets called several times. For instance, since PKG_NAME:=helloworld has already been declared through out the Makefile, I would just reference all the occurrence of the word helloworld with $(PKG_NAME) in my Makefile for the package.

(Last edited by mazilo on 5 Nov 2014, 14:12)

mazilo wrote:
KHAN85 wrote:

You wrote "woLRd" instead "woRLd", that's the error.

LOL ... looking for such a typo is like asking someone to search for a needle in a haystack with bare hands. To avoid that kind of typo, I prefer to use a variable to represent an entity that gets called several times. For instance, since PKG_NAME:=helloworld has already been declared through out the Makefile, I would just reference all the occurrence of the word helloworld with $(PKG_NAME) in my Makefile for the package.

i changed, here is my "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 Program written by Ken
endef

define Package/helloworld/description
    a sample OpenWRT helloworld program
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)/PKG_NAME $(1)/usr/bin
endef

$(eval $(call BuildPackage,PKG_NAME))

but it's still error, they warning me changing Makefile

ken@Ken-Laptop-Ubuntu:~/openwrt/openwrt-sdk$ make package/helloworld-compile V=99
ERROR: please fix package/helloworld/Makefile
Collecting package info: done
ERROR: please fix package/helloworld/Makefile
Collecting package info: done
#
# using defaults found in .config
#


*** End of OpenWrt configuration.
*** Execute 'make' to build the OpenWrt or try 'make help'.

make[1]: Entering directory `/home/ken/openwrt/openwrt-sdk'
make[1]: *** No rule to make target `package/helloworld-compile'.  Stop.
make[1]: Leaving directory `/home/ken/openwrt/openwrt-sdk'
make: *** [package/helloworld-compile] Error 2

i dont understand "rule to make target"
What's next i should do ?

mazilo wrote:
KHAN85 wrote:

You wrote "woLRd" instead "woRLd", that's the error.

LOL ... looking for such a typo is like asking someone to search for a needle in a haystack with bare hands. To avoid that kind of typo, I prefer to use a variable to represent an entity that gets called several times. For instance, since PKG_NAME:=helloworld has already been declared through out the Makefile, I would just reference all the occurrence of the word helloworld with $(PKG_NAME) in my Makefile for the package.

Then you will make other typo, $(PKG_NMAE) smile

_DS_ wrote:
mazilo wrote:
KHAN85 wrote:

You wrote "woLRd" instead "woRLd", that's the error.

LOL ... looking for such a typo is like asking someone to search for a needle in a haystack with bare hands. To avoid that kind of typo, I prefer to use a variable to represent an entity that gets called several times. For instance, since PKG_NAME:=helloworld has already been declared through out the Makefile, I would just reference all the occurrence of the word helloworld with $(PKG_NAME) in my Makefile for the package.

Then you will make other typo, $(PKG_NMAE) smile

That is tru. But, I have a template package that I used to port software to OpenWRT and I have yet to run into what you have said above.

_DS_ wrote:
mazilo wrote:
KHAN85 wrote:

You wrote "woLRd" instead "woRLd", that's the error.

LOL ... looking for such a typo is like asking someone to search for a needle in a haystack with bare hands. To avoid that kind of typo, I prefer to use a variable to represent an entity that gets called several times. For instance, since PKG_NAME:=helloworld has already been declared through out the Makefile, I would just reference all the occurrence of the word helloworld with $(PKG_NAME) in my Makefile for the package.

Then you will make other typo, $(PKG_NMAE) smile

mazilo wrote:

That is tru. But, I have a template package that I used to port software to OpenWRT and I have yet to run into what you have said above.

cant u help me guys ?

helloworld/compile, not helloworld-compile

_DS_ wrote:

helloworld/compile, not helloworld-compile

same error

ken@Ken-Laptop-Ubuntu:~/openwrt/openwrt-sdk$ make package/helloworld/compile V=99
ERROR: please fix package/helloworld/Makefile
Collecting package info: done
ERROR: please fix package/helloworld/Makefile
Collecting package info: done
#
# using defaults found in .config
#

*** End of OpenWrt configuration.
*** Execute 'make' to build the OpenWrt or try 'make help'.

make[1]: Entering directory `/home/ken/openwrt/openwrt-sdk'
make[1]: *** No rule to make target `package/helloworld/compile'.  Stop.
make[1]: Leaving directory `/home/ken/openwrt/openwrt-sdk'
make: *** [package/helloworld/compile] Error 2

You should use $(PKG_NAME), not just PKG_NAME.

_DS_ wrote:

You should use $(PKG_NAME), not just PKG_NAME.

i changed it still error but dont have details error, _DS_!

ken@Ken-Laptop-Ubuntu:~/openwrt/openwrt-sdk$ make package/helloworld/compile V=99
#
# using defaults found in .config
#


*** End of OpenWrt configuration.
*** Execute 'make' to build the OpenWrt or try 'make help'.

make[4]: Entering directory `/home/ken/openwrt/openwrt-sdk/package/helloworld'
make[4]: Leaving directory `/home/ken/openwrt/openwrt-sdk/package/helloworld'
make[1]: Entering directory `/home/ken/openwrt/openwrt-sdk'
make[2]: Entering directory `/home/ken/openwrt/openwrt-sdk/package/helloworld'
rm -rf /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld
mkdir -p /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL
echo "Package: helloworld" > /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL/control
echo "Version: 1" >> /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL/control
( DEPENDS=''; for depend in ; do DEPENDS=${DEPENDS:+$DEPENDS, }${depend##+}; done; echo "Depends: $DEPENDS"; echo "Provides: "; echo "Source: package/helloworld"; echo "Section: utils"; echo "Status: unknown ok not-installed"; echo "Essential: no"; echo "Priority: optional"; echo "Maintainer: OpenWrt Developers Team <openwrt-devel@openwrt.org>"; echo "Architecture: "; echo "Installed-Size: 0"; echo -n "Description: "; getvar V_Package_helloworld_description | sed -e 's,^[[:space:]]*, ,g'; ) >> /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL/control
chmod 644 /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL/control
(cd /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/CONTROL;  )
install -d -m0755 /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/usr/bin
install -m0755 /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/helloworld /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld/usr/bin
mkdir -p /home/ken/openwrt/openwrt-sdk/bin//packages
find /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld -name 'CVS' -o -name '.svn' -o -name '.#*' | xargs -r rm -rf
NM="-openwrt-linux-nm" STRIP="" STRIP_KMOD="-openwrt-linux-strip --strip-unneeded --remove-section=.comment --remove-section=.pdr --remove-section=.mdebug.abi32" /home/ken/openwrt/openwrt-sdk/scripts/rstrip.sh /home/ken/openwrt/openwrt-sdk/build_dir/target-_-/helloworld/ipkg-/helloworld
rstrip.sh: strip command not defined (STRIP variable not set)
make[2]: *** [/home/ken/openwrt/openwrt-sdk/bin//packages/helloworld_1_.ipk] Error 1
make[2]: Leaving directory `/home/ken/openwrt/openwrt-sdk/package/helloworld'
make[1]: *** [package/helloworld/compile] Error 2
make[1]: Leaving directory `/home/ken/openwrt/openwrt-sdk'
make: *** [package/helloworld/compile] Error 2

Target not defined.

_DS_ wrote:

Target not defined.

what does it mean? Can u give me some idea what should i do next ?
Thanks

Go to menuconfig and select cpu (and device) you compile for.

I think the error happens if one runs "make clean" in the SDK - it will remove the shipped .config and thus render the sdk unusuable.

I think that you need exchange makefiles. Now in src subdir exist makefile for package and in packege rootdir makefile for helloworld compilation.

123serge123 wrote:

I think that you need exchange makefiles. Now in src subdir exist makefile for package and in packege rootdir makefile for helloworld compilation.

Can u describe it clearer? I cant understand what u mean
Thanks

jow wrote:

I think the error happens if one runs "make clean" in the SDK - it will remove the shipped .config and thus render the sdk unusuable.

can u tell me more about "make clean" in which Makefile? bc i dont see any "clean" command in both make file
p/s: I'm so sry but my english isn't good so sometimes i dont know what it's rude

File

openwrt/openwrt-sdk/package/helloworld/Makefile

    CC = gcc
    FLAG = -Wall
    helloworld:
        $(CC) $(FLAG) helloworld.c -o hello

must be openwrt/openwrt-sdk/package/helloworld/src/Makefile
And openwrt/openwrt-sdk/package/src/helloworld/Makefile -> openwrt/openwrt-sdk/package/helloworld/Makefile.

123serge123 wrote:

File

openwrt/openwrt-sdk/package/helloworld/Makefile

    CC = gcc
    FLAG = -Wall
    helloworld:
        $(CC) $(FLAG) helloworld.c -o hello

must be openwrt/openwrt-sdk/package/helloworld/src/Makefile
And openwrt/openwrt-sdk/package/src/helloworld/Makefile -> openwrt/openwrt-sdk/package/helloworld/Makefile.

i think i type some wrong here
My dir in this post is swaped, in my laptop it's correct
i edited
thanks,sorry about that

(Last edited by hoangvu23108 on 6 Nov 2014, 14:46)

The discussion might have continued from here.