【问题标题】:How to build hello world recipe in yocto如何在 yocto 中构建 hello world 食谱
【发布时间】:2020-04-09 15:32:29
【问题描述】:
  1. C 文件

    int main() {
    printf("Hello, World!\n");
    return 0;
    } 
  1. helloworld.bb
DESCRIPTION = "Recipe created by bitbake-layers"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"


SRC_URI = "file://${BSPDIR}/poky/build-microchip/my_layer/recipes-example/helloworld/helloworld/helloworld.c"

S = "/home/user/my_dir/poky/build-microchip/conf"

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

do_install() {
        install -d ${D}${bindir}
        install -m 0755 helloworld ${D}${bindir}
} 
  1. 运行命令

bitbake helloworld

错误 do_compile() 块中的错误 helloworld.c 文件未找到

  1. 文件树
    build-microchip/my_layer/recipes-examples/
    └── helloworld
        ├── helloworld
        │   └── helloworld.c
        └── helloworld.bb

2个目录,2个文件

【问题讨论】:

  • 您确定${BSPDIR}/poky/build-microchip/my_layer/recipes-example/helloworld/helloworld/helloworld.c 吗?主要在${BSPDIR}?通常文件位于放置 bb 文件的 files 子目录下。
  • 只是为了仔细检查,您显示的“C 文件”的名称是什么?

标签: c cross-compiling yocto bitbake openembedded


【解决方案1】:

SRC_URI 中有绝对路径是相当不寻常的。

对于位于 build-microchip/my_layer/recipes-examples/helloworld/ 的名为 helloworld_0.1.bb 的配方,默认情况下(并按顺序)在以下目录之一 (FILESPATH[1]) 中为您的配方查找 SRC_URI 内容:

  1. build-microchip/my_layer/recipes-examples/helloworld/helloworld-0.1
  2. build-microchip/my_layer/recipes-examples/helloworld/helloworld
  3. build-microchip/my_layer/recipes-examples/helloworld/files

因此,您实际上不需要传递任何这些目录名称,Yocto 会自己找到它。您只需将路径 relative 传递给 SRC_URI 到上述路径之一。

如果你想使用配方当前目录之外的文件,通常externalsrc 类必须被继承(而且这样做通常不是一个好主意)。除了在 bbappends 的情况下,您使用 FILESEXTRAPATHS_prepend := "${THISDIR}/<otherdir>" 将另一个路径添加到列表中,这会将 ${THISDIR}/<otherdir> 放在上述列表的第一位。

请注意,FILESOVERRIDES[2] 的内容可以多一层“抽象”。如有疑问,请始终查看配方的 WORKDIR 中的 log.do_fetch,它会为您提供查找文件所遍历的所有路径以及遍历的顺序。

SRC_URI = "file://helloworld.c" 应该适合你。

我很确定 S 没有设置为 Yocto 所期望的。 S[3] 是 do_unpack 任务之后 Yocto 的源目录。这是 Yocto 设置的临时目录。它通常以${WORKDIR} 开头,这是给定配方的临时目录。仅在本地源的情况下,设置S = "${WORKDIR}",因为来自SRC_URI 的本地文件(以file:// 开头的文件)被提取器放入${WORKDIR}。默认设置为${WORKDIR}/<recipename-recipeversion>

do_compile 任务在B 中运行,默认设置为${S},在配方中设置不正确。这就是找不到您的文件的原因。[4]

TL;DR:

SRC_URI = "file://helloworld.c"
S = "${WORKDIR}"

[1]https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#var-FILESPATH

[2]https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#var-FILESOVERRIDES

[3]https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#var-S

[4]https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#ref-tasks-compile

【讨论】:

    【解决方案2】:

    您可以将 .c 文件放在您的食谱的子文件夹中,例如

    sources/poky/build-microchip/my_layer/recipes-example
    └── helloworld
        ├── files
        │   └── helloworld.c
        └── helloworld.bb
    

    并修改配方

    SRC_URI = "file://helloworld.c"
    

    当为配方调用时,Bitbake 有一个用于查找文件的默认文件夹列表,例如files子目录。

    通过这种方式,配方是可移植的,并且您可以确定可以找到文件。

    【讨论】:

    • 这如何解决问题?为什么 OP 不可能有更长的路径?
    • @Yunnosch 因为 OP 将文件放在与配方同名的子目录下,而不是在文件子目录中......为什么在 bitbake 查找嵌入的文件子目录时使用完整路径?至少,以我写的方式,它更便携。
    • edit 将该解释放入答案本身,而不是将其隐藏在此处的 cmets 中。另外,请考虑详细说明您的解释。
    • 谢谢。我会试试的
    • 感谢您解释为什么您的(更好和便携的)解决方案有效。但是 OP 不起作用的原因是什么?
    猜你喜欢
    • 2021-10-23
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多