Add applications and third-party libraries¶
Copyright © Quectel Wireless Solutions Co., Ltd. 2026. All rights reserved.
Overview¶
This document guides users to add custom applications and third-party libraries to the Yocto build system (using helloworld as an example). Through the steps in this document, you can:
Integrate custom code into Yocto projects
Generate IPK installation packages
Compile and use third-party library files
Integrate components into system images
Prerequisites¶
Environment requirements¶
Necessary development toolkits installed
Yocto project code cloned
Familiar with basic C programming
Understand Makefile and BitBake basics
Project directory structure¶
Create a custom meta layer. Recommended directory structure:
meta-custom/
├── conf/
│ └── layer.conf # Layer configuration file
├── recipes-apps/ # Application recipe directory
│ └── helloworld/
│ ├── files/
│ │ ├── helloworld.c # Application source code
│ │ ├── Makefile # Build script
│ │ └── helloworld.service # systemd service file
│ └── helloworld_1.0.bb # BitBake recipe
└── recipes-libs/ # Library recipe directory
└── lib-helloworld/
├── files/
│ ├── lib_helloworld.c # Library source code
│ ├── lib_helloworld.h # Library header file
│ └── Makefile # Build script
└── lib-helloworld_1.0.bb # BitBake recipe
Add custom applications¶
Create layer directory structure¶
Create directories¶
mkdir -p ${YOCTO_DIR}/layers/meta-custom/recipes-apps/helloworld/files
mkdir -p ${YOCTO_DIR}/layers/meta-custom/conf
Configure custom layer¶
Add the following to the layers/meta-custom/conf/layer.conf file:
BBPATH .= ":${LAYERDIR}"
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb"
LAYERDEPENDS_meta-custom = "core"
LAYERSERIES_COMPAT_meta-custom = "kirkstone"
Register layer to build system¶
Edit layers/meta-qcom-distro/conf/bblayers.conf by adding the custom layer path:
BBLAYERS = " \
${WORKSPACE}/layers/meta-custom \
"
Add to image recipe¶
Edit layers/meta-quectel/recipes-products/images/qcom-multimedia-image.bbappend by adding:
# Add the application
IMAGE_INSTALL:append = " helloworld"
# Add library files (if needed)
IMAGE_INSTALL:append = " \
lib-helloworld \
lib-helloworld-dev \
lib-helloworld-staticdev \
"
Create application source code¶
Write main program¶
Create helloworld.c in the meta-custom/recipes-apps/helloworld/files/ directory:
// helloworld.c
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
Write Makefile¶
Create Makefile in the meta-custom/recipes-apps/helloworld/files/ directory:
# Use compilation flags provided by Yocto
all: helloworld
helloworld: helloworld.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
clean:
rm -f helloworld
.PHONY: all clean
Create Systemd service file¶
Create helloworld.service in the meta-custom/recipes-apps/helloworld/files/ directory:
[Unit]
Description=Hello World Service
[Service]
Type=simple
ExecStart=/usr/bin/helloworld
[Install]
WantedBy=multi-user.target
Write BitBake recipe¶
Create helloworld_1.0.bb in the meta-custom/recipes-apps/helloworld/ directory:
SUMMARY = "Hello World application"
DESCRIPTION = "A simple Hello World application."
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
# Source code file list
SRC_URI = "file://helloworld.c \
file://Makefile \
file://helloworld.service"
# Set working directory
S = "${WORKDIR}"
# Inherit the systemd class
inherit systemd
# Define systemd service file name
SYSTEMD_SERVICE:${PN} = "helloworld.service"
# Configuration phase (skip)
do_configure() {
bbnote "skip do_configure"
}
# Compilation phase
do_compile() {
# Clean first
oe_runmake -f ${S}/Makefile clean
# Compile
oe_runmake -f ${S}/Makefile
}
# Installation phase
do_install() {
# Create the installation directory of the executable file
install -d ${D}${bindir}
# Install the executable file
install -m 0755 ${S}/helloworld ${D}${bindir}
# Create the systemd service directory
install -d ${D}${systemd_system_unitdir}
# Install the service file
install -m 0644 ${S}/helloworld.service ${D}${systemd_system_unitdir}
}
Build and install application¶
Configure build environment¶
Enter the code working directory and execute:
source quectel_build/compile/build.sh
Method 1: Compile and install IPK package separately¶
Step 1: Compile the application
bitbake helloworld
Step 2: Find the generated IPK package
find ~/build-qcom-wayland/tmp-glibc/deploy -name "helloworld*.ipk"
Example output:
/home/quectel/build-qcom-wayland/tmp-glibc/deploy/ipk/armv8-2a/helloworld_1.0-r0_armv8-2a.ipk
Step 3: Push to device
adb push helloworld_1.0-r0_armv8-2a.ipk /mnt
Step 4: Install the IPK package
Execute the following command on the device:
# Mount the file system as read-write mode
mount -o remount,rw /usr
# Install the IPK package
opkg install /mnt/helloworld_1.0-r0_armv8-2a.ipk
Step 5: Verify the installation
/usr/bin/helloworld
Expected output:
Hello, world!
Method 2: Compile the entire system image¶
Step 1: Configure the build parameters
# Users can customize the input parameters, and select from the prompted valid options
buildconfig QSM565DWF QSM565DWFPIARL1A01_BL01BP01K0M01_QDP_LP6.6.0XX.01.00X_V0X STD
Step 2: Compile the entire system
buildall
Step 3: Package the image
buildpackage
Step 4: Flash the image
The generated image is at quectel_build/QSM565DWFPIARL1A01_BL01BP01K0M01_QDP_LP6.6.0XX.01.00X_V0X.
Refer to the following documents for flashing:
Step 5: Verify the installation
After the flashing is complete, execute the following command on the device:
/usr/bin/helloworld
Expected output:
Hello, world!
Add third-party libraries¶
Create library files¶
Create directory¶
mkdir -p ${YOCTO_DIR}/layers/meta-custom/recipes-libs/lib-helloworld/files
Create library header file¶
Create lib_helloworld.h in the meta-custom/recipes-libs/lib-helloworld/files/ directory:
// lib_helloworld.h
#ifndef LIB_HELLO_H
#define LIB_HELLO_H
void hello_print(const char* name);
#endif
Create library source code¶
Create lib_helloworld.c in the meta-custom/recipes-libs/lib-helloworld/files/ directory:
// lib_helloworld.c
#include <stdio.h>
#include "lib_helloworld.h"
void hello_print(const char* name) {
printf("[LIB] Hello, %s!\n", name);
}
Write Makefile¶
Create Makefile in the meta-custom/recipes-libs/lib-helloworld/files/ directory:
LIB_VERSION = 1.0
all:
${CC} ${CFLAGS} -fPIC -c lib_helloworld.c -o lib_helloworld.o
${CC} ${CFLAGS} -fPIC -shared lib_helloworld.o -o libhello.so.${LIB_VERSION} \
-Wl,-soname,libhello.so.1 ${LDFLAGS}
ar rcs libhello.a lib_helloworld.o
ln -sf libhello.so.${LIB_VERSION} libhello.so
ln -sf libhello.so.${LIB_VERSION} libhello.so.1
clean:
rm -f libhello.so* lib_helloworld.o libhello.a
Write BitBake recipe¶
Create lib-helloworld_1.0.bb in the meta-custom/recipes-libs/lib-helloworld/ directory:
SUMMARY = "Hello World Library"
SECTION = "libs"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://lib_helloworld.c \
file://lib_helloworld.h \
file://Makefile"
S = "${WORKDIR}"
EXTRA_OEMAKE = "'CC=${CC}' 'CFLAGS=${CFLAGS} -fPIC' 'LDFLAGS=${LDFLAGS}'"
do_install() {
# Create target directories
install -d ${D}${libdir}
install -d ${D}${includedir}
# Install shared library and symbolic links
install -m 0755 ${S}/libhello.so.${PV} ${D}${libdir}/
ln -sf libhello.so.${PV} ${D}${libdir}/libhello.so
ln -sf libhello.so.${PV} ${D}${libdir}/libhello.so.1
# Install the static library
install -m 0644 ${S}/libhello.a ${D}${libdir}/
# Install the header file
install -m 0644 ${S}/lib_helloworld.h ${D}${includedir}/
}
# Allocate the package files
FILES:${PN} = " \
${libdir}/libhello.so.1 \
${libdir}/libhello.so.${PV} \
"
FILES:${PN}-dev = " \
${libdir}/libhello.so \
${includedir}/lib_helloworld.h \
"
FILES:${PN}-staticdev = " \
${libdir}/libhello.a \
"
Build and use third-party libraries¶
Configure build environment¶
source quectel_build/compile/build.sh
Method 1: Compile and install separately¶
Step 1: Compile the library
bitbake lib-helloworld
Step 2: Find the generated library files
find ./* -name "libhello*"
Step 3: Push to device
adb push libhello.so libhello.so.1 libhello.so.1.0 libhello.a /usr/lib
Step 4: Fix permissions and symbolic links
Execute on the device:
# Set execute permissions
chmod 755 /usr/lib/libhello.so*
chmod 644 /usr/lib/libhello.a
# Rebuild symbolic links
cd /usr/lib
ln -sf libhello.so.1.0 libhello.so.1
ln -sf libhello.so.1 libhello.so
Step 5: Write the test program
Create the static library test program static_test_helloworld.c:
#include <stdio.h>
void hello_print(const char*);
int main() {
printf("static lib test\n");
hello_print("world");
return 0;
}
Create the dynamic library test program dynamic_test_helloworld.c:
#include <stdio.h>
void hello_print(const char*);
int main() {
printf("dynamic lib test\n");
hello_print("world");
return 0;
}
Step 6: Compile and run the test program
Static library test:
gcc static_test_helloworld.c -lhello -static -o static_hello
./static_hello
Expected output:
static lib test
[LIB] Hello, world!
Dynamic library test:
gcc dynamic_test_helloworld.c /usr/lib/libhello.so -o dynamic_hello
./dynamic_hello
Expected output:
dynamic lib test
[LIB] Hello, world!
Method 2: Compile the entire system image¶
Compile and flash
Refer to the steps in the "Method 2: Compile the entire system image" section of the "Add custom applications" chapter for compilation and flashing.
Verify library files
After the flashing is complete, check library files on the device:
ls -l /usr/lib/libhello*
Expected output:
-rw-r--r--. 2 root root 5002 Jan 1 1970 /usr/lib/libhello.a
lrwxrwxrwx. 1 root root 15 Jul 25 06:26 /usr/lib/libhello.so -> libhello.so.1.0
lrwxrwxrwx. 1 root root 15 Jul 25 06:26 /usr/lib/libhello.so.1 -> libhello.so.1.0
-rwxr-xr-x. 2 root root 5968 Jan 1 1970 /usr/lib/libhello.so.1.0
Run test program
Static library test:
gcc static_test_helloworld.c -lhello -static -o static_hello
./static_hello
Expected output:
static lib test
[LIB] Hello, world!
Dynamic library test:
gcc dynamic_test_helloworld.c /usr/lib/libhello.so -o dynamic_hello
./dynamic_hello
Expected output:
dynamic lib test
[LIB] Hello, world!
Notes¶
Layer priority: Ensure that the custom layer configuration is correct to avoid conflicts with other layers
License declaration: Must correctly set LICENSE and LIC_FILES_CHKSUM
File permissions: Pay attention to the permission settings of the executable and library files
Symbolic links: Dynamic library symbolic links must be correctly set
Dependencies: If the library depends on other packages, declare DEPENDS in the recipe
Version management: It is recommended to use version numbers to manage library files
FAQs¶
Q1: BitBake compilation failed?¶
Check items:
Is the recipe syntax correct
Are source file paths correct
Does the LICENSE file exist
Q2: IPK installation failed?¶
Solution:
Ensure that the filesystem is mounted as read-write mode
Check if disk space is sufficient
View opkg error logs
Q3: Dynamic library not found?¶
Solution:
Check LD_LIBRARY_PATH environment variable
Confirm symbolic links are correct
Run
ldconfigto update the library cache
Summary¶
Through the guidance in this document, in the Yocto environment, you can:
Create custom applications and libraries
Generate IPK installation packages for separate deployment
Integrate components into system images
Verify and test custom components
After mastering these skills, you can expand and customize system functionalities according to actual needs.