The basic steps are as follows:
- Create a user application by running
petalinux-create -t apps
from inside a PetaLinux project on your workstation:$ cd <plnx-proj-root> $ petalinux-create -t apps --template c --name <user-library-name> --enable
For example:
$ petalinux-create -t apps --template c --name libsample --enable
Note: If the application name has '_' or uppercase letters or starts with an uppercase letter, see Recipe Name has ' _ ' or Uppercase Letters or Starts with an Uppercase Letter.The new application sources can be found in the <plnx-proj-root>/project-spec/meta-user/recipes-apps/libsample directory.
- Change to the newly created application directory.
$ cd <plnx-proj-root>/project-spec/meta-user/recipes-apps/libsample
- Edit the file project-spec/meta-user/recipes-apps/libsample/libsample.bb.
The file should look like the following.
# # This file is the libsample recipe. # SUMMARY = "Simple libsample application" SECTION = "libs" LICENSE = "MIT" LIC_FILES_CHKSUM ="file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" SRC_URI = "file://libsample.c \ file://libsample.h \ file://Makefile \ " S = "${WORKDIR}" PACKAGE_ARCH = "${MACHINE_ARCH}" PROVIDES = "sample"TARGET_CC_ARCH += "${LDFLAGS}" do_install() { install -d ${D}${libdir} install -d ${D}${includedir} oe_libinstall -so libsample ${D}${libdir} install -d -m 0655 ${D}${includedir}/SAMPLE install -m 0644 ${S}/*.h ${D}${includedir}/SAMPLE/ } FILES_${PN} = "${libdir}/*.so.* ${includedir}/*" FILES_${PN}-dev = "${libdir}/*.so"
- Edit the file project-spec/meta-user/recipes-apps/libsample/files/libsample.c.
The file should look like the
following:
#include <stdio.h> #include "libsample.h" int function() { printf("Hello World!\n"); return 0; } void samplelib() { printf("Hello, Welcome to PetaLinux -- samplelib !\n"); }
- Create a new file project-spec/meta-user/recipes-apps/libsample/files/libsample.h
and add below line.
void samplelib();
- Edit the file project-spec/meta-user/recipes-apps/libsample/files/Makefile. Refer to the makefile content at https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842475/PetaLinux+Yocto+Tips#PetaLinuxYoctoTips-HowtoAddPre-builtLibrariesinPetaLinuxorYoctoRecipes for more details.
- Build
recipe.
petalinux-build -c libsample