Development Examples

Building HelloWorld without BitBake

The following example shows how to build a simple C application, transfer it to the device using SCP, and run it over an SSH connection.

# set PATH to include the toolchain 
# (assumes OETREE is set from env-oe.sh and build system is x86_64)
export PATH=$PATH:${OETREE}/build/tmp/sysroots/x86_64-linux/usr/armv5te/bin

# compile and link helloworld.c
arm-corecdp-linux-gnueabi-gcc -o helloworld helloworld.c

# copy to device in /usr/bin/
scp helloworld root@192.168.2.1:/usr/bin/

# ssh to device and run it
ssh root@192.168.2.1
helloworld

Building HelloWorld with a BitBake recipe

The following example shows how to package a simple C application using a BitBake recipe. First, the recipe is created. Then the package is built and copied to the device using SCP. Lastly, opkg is used to install the package on the device.

# create a recipe
cd ${OETREE}/user-layer/recipes
mkdir helloworld
cd helloworld

# (create helloworld_1.0.0.bb, see below for contents)
# (create helloworld.c)

# build package
cd ${OETREE}
bitbake helloworld

# copy the package to the device
scp build/tmp/deploy/eglibc/ipk/armv5te/helloworld_1.0.0-r0.10_armv5te.ipk  root@192.168.2.1:/var/tmp/

# install the package
ssh root@192.168.2.1
cd /var/tmp
opkg install helloworld_1.0.0-r0.10_armv5te.ipk

# run it
helloworld

To install the helloworld package into a custom filesystem image that can be flashed into the device, see Creating a Custom Image

helloworld_1.0.0.bb

For further explanation of this recipe, see Writing BitBake Recipes

DESCRIPTION = "HelloWorld"
SECTION = "examples"
LICENSE = "GPL"
 
SRC_URI = "file://helloworld.c"
 
S = "${WORKDIR}"
 
do_compile() {
    ${CC} ${CFLAGS} ${LDFLAGS} helloworld.c -o helloworld
}
 
do_install() {
    install -d ${D}${bindir}
    install -m 0755 helloworld ${D}${bindir}
}