如何在yocto中编译基本的c文件

ani*_*han -1 c yocto

我正在研究yocto,我想在yocto中编译一些c文件并将它们安装到外部文件系统.在此之前,我尝试创建一个单独的reciepe并从中编译c代码.我无法编译它.

Dav*_*san 15

我不太清楚这个问题,因为它不够准确.

在配方树中包含C文件

如果您想在配方中拥有C文件,请使用如下文件树:

recipe-example/example/example_0.1.bb
recipe-example/example/example-0.1/helloworld.c
Run Code Online (Sandbox Code Playgroud)

您可以在使用创建新图层时生成此示例

yocto-layer <your-layer-name>
Run Code Online (Sandbox Code Playgroud)

你的bb文件看起来像这样:

#
# 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}
}
Run Code Online (Sandbox Code Playgroud)

它将编译hello world文件并将其安装到您的映像上的/ usr/bin中.

来自Git回购

您也可以从git存储库编译,我建议您阅读yocto文件夹中的手册和示例.这是一个有关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
}
Run Code Online (Sandbox Code Playgroud)

它是从git存储库获取,应用git生成的补丁,使用oe_runmake使用makefile进行编译.

随着devtool

在评论中已经询问过如何使用devtool添加配方.我们仍将再次使用wiringPi作为示例.下载它做 https://github.com/WiringPi/WiringPi Makefile是文件夹wiringPi.然后你可以做

devtool add <name_of_recipe> <path_to_Makefile_folder>
Run Code Online (Sandbox Code Playgroud)

照顾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
Run Code Online (Sandbox Code Playgroud)

这产生如下配方:

# 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}'
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以编辑配方以适合您的配置