Steps to Add Custom Libraries - 2020.2 English

PetaLinux Tools Documentation Reference Guide (UG1144)

Document ID
Release Date
2020.2 English

The basic steps are as follows:

  1. 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.

  2. Change to the newly created application directory.
    $ cd <plnx-proj-root>/project-spec/meta-user/recipes-apps/libsample
  3. Edit the file project-spec/meta-user/recipes-apps/libsample/

    The file should look like the following.

    # This file is the libsample recipe.
    SUMMARY = "Simple libsample application"
    SECTION = "libs"
    LIC_FILES_CHKSUM ="file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
    SRC_URI = "file://libsample.c \
        file://libsample.h \
        file://Makefile \
    S = "${WORKDIR}"
    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"
  4. 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");
  5. Create a new file project-spec/meta-user/recipes-apps/libsample/files/libsample.h and add below line.
    void samplelib();
  6. Edit the file project-spec/meta-user/recipes-apps/libsample/files/Makefile. Refer to the makefile content at for more details.
  7. Build recipe.
    petalinux-build -c libsample