2

I am working on yocto, I want to compile some C files in yocto and install the resulting binary to external filesystem. Before doing that I tried creating a separate reciepe and compile c code from it. I am unable to compile it.

2
  • 1
    Please post a Minimal, Complete, and Verifiable example. Commented Jun 8, 2016 at 14:53
  • 1
    OK, thanks for sharing your problem, do you have a specific question, too? Commented Jun 8, 2016 at 15:13

2 Answers 2

33

I am not sure to understand the question since it is not precise enough.

Including C files in recipe tree

If you want to have the C files in your recipe, having a file tree like this:

recipe-example/example/example_0.1.bb
recipe-example/example/example-0.1/helloworld.c

You can generate this example when you create a new layer using

yocto-layer <your-layer-name>

Your bb file will look like this:

#
# This file was derived from the 'Hello World!' example recipe in the
# Yocto Project Development Manual.
#
SUMMARY = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://helloworld.c"

S = "${WORKDIR}"

do_compile() {
         ${CC} helloworld.c -o helloworld
}

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

It will compile the hello world file and install it into /usr/bin on your image.

From a Git repo

You also can compile from a git repository, I advise you to read the manual and examples in your yocto folder. Here is an example here of wiringPi:

DESCRIPTION = "A library to control Raspberry Pi GPIO channels"
HOMEPAGE = "https://projects.drogon.net/raspberry-pi/wiringpi/"
SECTION = "devel/libs"
LICENSE = "LGPLv3+"
LIC_FILES_CHKSUM = "file://COPYING.LESSER;md5=e6a600fd5e1d9cbde2d983680233ad02"

# tag 2.29
SRCREV = "d79506694d7ba1c3da865d095238289d6175057d"

S = "${WORKDIR}/git"

SRC_URI = "git://git.drogon.net/wiringPi \
           file://0001-Add-initial-cross-compile-support.patch \
           file://0001-include-asm-ioctl.h-directly-for-_IOC_SIZEBITS.patch \
           "

COMPATIBLE_MACHINE = "raspberrypi"

CFLAGS_prepend = "-I${S}/wiringPi -I${S}/devLib"

EXTRA_OEMAKE += "'INCLUDE_DIR=${D}${includedir}' 'LIB_DIR=${D}${libdir}'"
EXTRA_OEMAKE += "'DESTDIR=${D}/usr' 'PREFIX=""'"

do_compile() {
    oe_runmake -C devLib
    oe_runmake -C wiringPi
    oe_runmake -C gpio 'LDFLAGS=${LDFLAGS} -L${S}/wiringPi -L${S}/devLib'
}

do_install() {
    oe_runmake -C devLib install
    oe_runmake -C wiringPi install
    oe_runmake -C gpio install
}

It is fetching from a git repository, applying patches generated by git, using oe_runmake to compile with the makefiles.

With devtool

It has been asked in a comment on how to add a recipe with devtool. We will still use wiringPi as an example again. Download it doing https://github.com/WiringPi/WiringPi The Makefile is is the folder wiringPi. You can then do

devtool add <name_of_recipe> <path_to_Makefile_folder>

Take care of the warning from devtool

NOTE: Creating workspace layer in /home/dbensoussan/new_poky/poky/build/workspace
NOTE: Enabling workspace layer in bblayers.conf
NOTE: Using source tree as build directory since that would be the default for this recipe
NOTE: Recipe /home/dbensoussan/new_poky/poky/build/workspace/recipes/project/project.bb has been automatically created; further editing may be required to make it fully functional

This is generating the recipe as follow:

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)
#
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "Unknown"
LIC_FILES_CHKSUM = "file://COPYING.LESSER;md5=e6a600fd5e1d9cbde2d983680233ad02"

# No information for SRC_URI yet (only an external source tree was specified)
SRC_URI = ""


# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # Specify any needed configure commands here
    :
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    oe_runmake
}

do_install () {
    # This is a guess; additional arguments may be required
    oe_runmake install 'DESTDIR=${D}'
}

You can then edit your recipe to suit your configuration

With externalsrc

It is possible to use a directory present on the filesystem by using externalsrc. I did not try it myself, nor have I the workspace ready to do, but @71GA in the comment tested the tutorial from the Koan software company https://wiki.koansoftware.com/index.php/Building_Software_from_an_External_Source and it worked. I will copy the content here:

in this case use the externalsrc class - you can inherit this in the original bb recipe or a bbappend:

inherit externalsrc
EXTERNALSRC = "/path/to/sources"

Depending on the type of build (eg, 'inherit module' for out of tree Linux kernel modules) you may or may not need to set EXTERNALSRC_BUILD.

inherit externalsrc
EXTERNALSRC = "/some/path"
EXTERNALSRC_BUILD = "/some/path"

If you're going to use it across a number of recipes you can inherit it globally at the configuration level (perhaps via an inc file that you include/require there):

INHERIT += "externalsrc"
EXTERNALSRC_pn-<recipename> = "/path/to/sources"

Recipe example using an external source for nInvaders package

#
# Recipe example with externalsrc
#
# (C)2019 Marco Cavallini - KOAN - <https://koansoftware.com>
#

LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""

inherit externalsrc

EXTERNALSRC = "/home/koan/yocto-qemuarm-sumo/ninvaders-0.1.1"
EXTERNALSRC_BUILD = "${EXTERNALSRC}"

DEPENDS = "ncurses"

EXTRA_OEMAKE = "-e"


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

FILES_${PN} = "${bindir}/*"
Sign up to request clarification or add additional context in comments.

10 Comments

If possible, could you show how to do it with devtool? Thank you. I still need some more information on how to work with that.
@CharlesChau, I just edited my answer and added an example with devtool
Hi David Bensoussan, Thanks for your answer, i used recipes-example as mentioned above. when i execute bitbake -b /PATH_TO_BB/example_0.1.bb it is generating a executable. when i am running bitbake core-image-minimal, it is not compiling any file, do i need to any extra changes for this
@71GA I don't have a yocto workspace to test it at the moment and confirm it works, but have you checked this link? wiki.koansoftware.com/index.php/…
@DavidBensoussan It looks like do_compile() is actually not even needed! So that website is correct.
|
1

You can just go to the official documentation to find your answer.

In the chapter 5.2 Writting a New Recipe of the yocto mega-manual, the very first example is exactly is what you need (Single .c File Package (Hello World!)).

4 Comments

Link does not work.
@71GA Updated links and text
Links are dead again.
@TheBerga updated again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.