Fail to compile Hello world tutorial

Hello everyone!

I fail to compile the simple Hello world program of the tutorial.

I think it is because i am not using openwrt gcc, but my linux gcc.

Problem 1:

make[3] -C mypackages/helloworld compile
    ERROR: package/feeds/mypackages/helloworld failed to build.
make -r world: build failed. Please re-run make with -j1 V=s or V=sc for a higher verbosity level to see what's going on
make: *** [/home/francis/Documents/rutos-ramips-trb2m-gpl/include/toplevel.mk:238: world] Error 1

Details to problem 1:

make[3]: Entering directory '/home/francis/Documents/rutos-ramips-trb2m-gpl/mypackages/helloworld'
rm -rf /home/francis/Documents/rutos-ramips-trb2m-gpl/build_dir/target-mipsel_24kc_musl/helloworld-1.0/.pkgdir/helloworld.installed /home/francis/Documents/rutos-ramips-trb2m-gpl/build_dir/target-mipsel_24kc_musl/helloworld-1.0/.pkgdir/helloworld
mkdir -p /home/francis/Documents/rutos-ramips-trb2m-gpl/build_dir/target-mipsel_24kc_musl/helloworld-1.0/.pkgdir/helloworld
install -d -m0755 /home/francis/Documents/rutos-ramips-trb2m-gpl/build_dir/target-mipsel_24kc_musl/helloworld-1.0/.pkgdir/helloworld/usr/bin
/home/francis/Documents/rutos-ramips-trb2m-gpl/build_dir/target-mipsel_24kc_musl/helloworld-1.0/helloworld /home/francis/Documents/rutos-ramips-trb2m-gpl/build_dir/target-mipsel_24kc_musl/helloworld-1.0/.pkgdir/helloworld/usr/bin
bash: line 1: /home/francis/Documents/rutos-ramips-trb2m-gpl/build_dir/target-mipsel_24kc_musl/helloworld-1.0/helloworld: cannot execute binary file: Exec format error
make[3]: *** [Makefile:47: /home/francis/Documents/rutos-ramips-trb2m-gpl/build_dir/target-mipsel_24kc_musl/helloworld-1.0/.pkgdir/helloworld.installed] Error 126
make[3]: Leaving directory '/home/francis/Documents/rutos-ramips-trb2m-gpl/mypackages/helloworld'
time: package/feeds/mypackages/helloworld/compile#0.16#0.03#0.19
    ERROR: package/feeds/mypackages/helloworld failed to build.
make[2]: *** [package/Makefile:114: package/feeds/mypackages/helloworld/compile] Error 1
make[2]: Leaving directory '/home/francis/Documents/rutos-ramips-trb2m-gpl'
make[1]: *** [package/Makefile:108: /home/francis/Documents/rutos-ramips-trb2m-gpl/staging_dir/target-mipsel_24kc_musl/stamp/.package_compile] Error 2
make[1]: Leaving directory '/home/francis/Documents/rutos-ramips-trb2m-gpl'
make: *** [/home/francis/Documents/rutos-ramips-trb2m-gpl/include/toplevel.mk:238: world] Error 2

Problem 2 (maybe a problem):

Setup:
Xubuntu on virtualbox. Target TRB246 from Teltonika.

Makefile:

include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1

SOURCE_DIR:=/home/francis/Documents/rutos-ramips-trb2m-gpl/helloworld
#PKG_BUILD_DIR:=build

include $(INCLUDE_DIR)/package.mk

define Package/helloworld
        SECTION:=examples
        CATEGORY:=Examples
        TITLE:=Hello, World!
endef

define Package/helloworld/description
        A simple "Hello, world!" -application
endef

define Build/Prepare
        mkdir -p $(PKG_BUILD_DIR)
        cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
        $(Build/Patch)
endef

define Build/Compile
        $(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.c
        $(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o
endef

define Package/helloworld/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INCLUDE_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
endef

$(eval $(call BuildPackage,helloworld))

Inside feeds.conf.default:

src-git packages https://github.com/openwrt/packages.git^65057dcbb5de371503c9159de3d45824bec482e0
src-git luci https://github.com/openwrt/luci.git^3b3c2e5f9f82372df8ff01ac65668be47690dcd5
src-git routing https://github.com/openwrt/routing.git^c30c9ffc93702365439a7647244a052531f2e957
src-git telephony https://github.com/openwrt/telephony.git^7f73a9ad19269dcddcb7fc26e03a9823717587bb
src-link mypackages /home/francis/Documents/rutos-ramips-trb2m-gpl/mypackages

image

Do you know how to solve that?

Thank you in advance!

$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin

Great! You have a good eye, thank you very much!

Weird error

The explaination: $(INCLUDE_BIN) is an unknown (undefined) variable, so it expands to the empty string which turns the command line into /...temporary.build.dir.../helloworld /...temporary.install.dir.../usr/bin, so an invocation of the just compiled "helloworld" program with a ".../usr/bin" path as argument.

This attempt to run the helloworld executable (instead of copying it somewhere) did result in .../helloworld: cannot execute binary file: Exec format error since your host system CPU (presumably x86) can't execute a MIPS executable. The resulting nonzero error exit code was propagated up and caused the "make" process to fail.

1 Like