OpenWrt Forum Archive

Topic: Build package binary only

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

Hi,

Is it possible to build the binary of a package only?
I don't want to install the .ipk every time i want to test my application ,or build the whole rootfs.

When i run the plane binary found in the bin/ramips-glibc/package folder (copied to target) i get errors.

Thanks

You need to first compile the full firmware including your package in order to get all required libraries etc. in place.
If there are any settings or dependencies, you need to opkg install the *.ipk once , so that all necessary files are in the router.
After you have installed the *.ipk once, you can replace individual files in the router.

And you can compile the package only:
make package/yourpackage/clean
make package/yourpackage/compile

Typically the compiled binaries should be found in build_dir/target.../package.../src
E.g. nano binary in my ar71xx based system: build_dir/target-mips_34kc_musl-1.1.14/nano-2.5.3/src/nano
(depends on the package, if there is "src" dir)

Ps. your bin/ramips-glibc/package sounds strange. Typically only the firmware images and *.ipk files are in bin/

EDIT:
I now noticed that you have asked several questions around the same topic. To get more useful answers, you should show the package Makefile. Or if you try to crosscompile directly with gcc, show the exact commands you use for compiling.

(Last edited by hnyman on 27 May 2016, 08:52)

Thanks for the response.
I did compile the whole system and use it to boot the device from a tftp server, contains of cource glibc for printf.
The helloworld binary is in the rootfs and i can run it successfully, the problem occurs when i compile it as a standalone package and upload it to the target, i don't want to install it via opkg but run the binary.

I get the following error:
./helloworld: line 1: syntax error: unexpected word (expecting ")")

I thought it was the directory bin/ramips-glibc/package but let me check when i get home, i will also opload the Makefile.

When i cross compile directly with the generated toolchain i get a 'Segmentation fault' when i execute the binary, so i gave that up for now.

jdw wrote:

I get the following error:
./helloworld: line 1: syntax error: unexpected word (expecting ")")

That error sounded like a wrong platform for the binary file.

Well i guess that is not the problem because when i 'file' the program build in the image i get the following:
$ file helloworld
helloworld: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 2.6.32, stripped

When i 'file' the program i uploaded to the target i get:
openwrt/build_dir/target-mipsel_24kec+dsp_glibc-2.21/helloworld/helloworld: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 2.6.32, not stripped

So the only real difference is that the second one is not stripped, can this be a problem??

hnyman the binary i want to use is indeed in 'openwrt/build_dir/target-mipsel_24kec+dsp_glibc-2.21/helloworld/helloworld'

I use the following makefile in the package dir:

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
    DESCRIPTION:=\
    If you can't figure out what this program does, \\\
    you're probably brain-dead and need immediate \\\
    medical attention.
endef

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/
endef

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

$(eval $(call BuildPackage,helloworld))


And this makefile in the src dir:

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

clean:
    rm *.o helloworld


This is my helloworld:

#include <stdio.h>

int main()
{
    printf("Hello OpenWRT\r\n");
    return 0;
}

Thanks so far

jdw wrote:

Well i guess that is not the problem because when i 'file' the program build in the image i get the following:
$ file helloworld
helloworld: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 2.6.32, stripped

When i 'file' the program i uploaded to the target i get:
openwrt/build_dir/target-mipsel_24kec+dsp_glibc-2.21/helloworld/helloworld: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 2.6.32, not stripped

So the only real difference is that the second one is not stripped, can this be a problem??

AFAICT, that does not matter. Can you also try to `file /bin/busybox` and see if the result is the same platform?

The discussion might have continued from here.