You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过bitbake将C文件添加到Yocto自定义层并构建镜像问题求助

Yocto添加C程序到自定义层问题修复方案

一、修复example_0.1.bb配方错误

你当前的配方存在多处语法和逻辑错误,修改后完整内容如下:

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}"
# 导入交叉编译工具链相关配置
inherit base

do_compile(){
    # 变量引用用${}而非$(),$()是shell命令替换语法,会误把CC当成命令执行
    # 线程库参数为-lpthread,不是-lpthreads
    ${CC} ${CFLAGS} ${LDFLAGS} threading.c -o threads -lpthread
}

do_install(){
    install -d ${D}${bindir}
    # 修复路径拼写错误,去掉末尾多余的s,不要错误拆分命令行
    install -m 0755 threads ${D}${bindir}
}

# 声明配方生成的安装文件,防止打包时丢失
FILES:${PN} = "${bindir}/threads"

同时确认你的threading.c文件放在example_0.1.bb同级的files目录下,对应自定义层路径为meta-custLayer/recipes-example/example/files/threading.c。

二、修复镜像依赖配置错误

你当前在镜像配置中添加的运行时依赖错误,不要依赖二进制文件名threads,要依赖配方名example。
不要直接修改Poky原生层的core-image-minimal.bb,在你的自定义层创建meta-custLayer/recipes-core/images/core-image-minimal.bbappend,内容如下:

IMAGE_INSTALL:append = " example"

三、验证执行

  • 执行bitbake example确认配方编译没有错误
  • 执行bitbake core-image-minimal构建完整镜像
  • 启动QEMU后,在终端直接执行threads命令即可运行你的C程序

内容的提问来源于stack exchange,提问作者Sajil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 13:45:05