Search code examples
multithreadingembedded-linuxyoctobitbakeyocto-recipe

Cannot add C file to Yocto Layer using bitbake


I have a C file binary to add as custom layer in the yocto and run in qemu. I have created layer using bitbake-layers create-layer meta-custLayer and added using bitbake-layers add-layer meta-custLayer. The file tree of meta-custLayer is as:
file tree

The example_0.1.bb file has the following:

SUMMARY = "bitbake-layers recipe"
DESCRIPTION = "Recipe created by bitbake-layers"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://threading.c"

S = "${WORKDIR}"
TARGET_CC_ARCH += "${LDFLAGS}"

do_compile(){
    $(CC) threading.c -o threads -lpthreads
}


do_install(){
    install -d ${D}${bindir}
    install -m 0755 threads
${D}${bindir}s
}

When the command bitbake example is executed, this is the output:

ERROR: example-0.1-r0 do_compile: Execution of '/home/sajil/edm_yocto/sources/poky/build/tmp/work/core2-64-poky-linux/example/0.1-r0/temp/run.do_compile.1806553' failed with exit code 127:
/home/sajil/edm_yocto/sources/poky/build/tmp/work/core2-64-poky-linux/example/0.1-r0/temp/run.do_compile.1806553: 99: CC: not found
/home/sajil/edm_yocto/sources/poky/build/tmp/work/core2-64-poky-linux/example/0.1-r0/temp/run.do_compile.1806553: 99: threading.c: not found
WARNING: exit code 127 from a shell command.

when bitbake core-image-minimal is executed, terminal shows that threads is unbuildable and runs into error:

ERROR: Nothing RPROVIDES 'threads' (but /home/sajil/edm_yocto/sources/poky/meta/recipes-core/images/core-image-minimal.bb RDEPENDS on or otherwise requires it)
NOTE: Runtime target 'threads' is unbuildable, removing...
Missing or unbuildable dependency chain was: ['threads']
ERROR: Required build target 'core-image-minimal' has no buildable providers.
Missing or unbuildable dependency chain was: ['core-image-minimal', 'threads']

I checked the path of the custom layer directory, being correct. I am clueless about the errors I am confronting.

For now my task is to run the C-file (adding it as a layer) on QEMU. I am unable to build the image for the same.

I would appreciate some help and insights!


Solution

  • There is multiple issues on your recipe:

    • Your do_compile command does not indicate where to find your .c file
    • You should use ${CC} instead of $(CC)
    • lpthread does not end with and s
    do_compile() {
        ${CC} ${S}/threading.c -o ${S}/threads -lpthread
    }
    
    • Your do_install does not provide the correct path to your binary:
    do_install() {
        install -d ${D}${bindir}
        install -m 0755 ${WORKDIR}/threads ${D}${bindir}
    }
    
    • At the end you should populate the packages:
    FILES_${PN} = "${bindir}"
    

    Edit about threads unbuildable:

    threads is unbuildable because the recipe does not mention that the package is threads.

    Here you have some options:

    • Rename your recipe to threads_0.1.bb (I recommend you to use a less generic name)
    • use the PACKAGES variable in your recipe. You will need to modify the FILES_* variable too. (a bit complicated if you are new to Yocto)
    • Use the current recipe name, and change the IMAGE_INSTALL += "threads" to IMAGE_INSTALL += "example"