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

如何在Yocto Recipe中添加特定版本(3.19.6)的Protobuf?

在Yocto Recipe中添加Protobuf 3.19.6的步骤与配置

1. 创建/修改Protobuf Recipe文件

Yocto官方层(如meta-openembedded)通常包含Protobuf的Recipe,但版本未必是3.19.6。你可以在自定义layer中创建对应版本的Recipe:

  • 在自定义layer下创建目录:mkdir -p recipes-support/protobuf
  • 新建Recipe文件:touch recipes-support/protobuf/protobuf_3.19.6.bb

2. 核心配置项填写

在protobuf_3.19.6.bb中添加以下关键配置:

# 版本号定义
PV = "3.19.6"

# 源码包地址(官方GitHub发布包)
SRC_URI = "https://github.com/protocolbuffers/protobuf/releases/download/v${PV}/protobuf-all-${PV}.tar.gz"

# 源码包SHA256校验值(可从官方发布页获取或自行计算)
SRC_URI[sha256sum] = "a1d65a485f178a53f42b1a6e7959887a3b7124d9d0d9c307e12209f1e4e4e1a3"

# 源码解压后的工作目录
S = "${WORKDIR}/protobuf-${PV}"

# 编译依赖
DEPENDS = "cmake zlib"

# CMake编译参数配置
EXTRA_OECMAKE = " \
    -Dprotobuf_BUILD_SHARED_LIBS=ON \
    -Dprotobuf_BUILD_STATIC_LIBS=ON \
    -Dprotobuf_BUILD_TESTS=OFF \
    -Dprotobuf_WITH_ZLIB=ON \
    -DCMAKE_INSTALL_PREFIX=${D}${prefix} \
"

# 安装文件指定(可选,默认CMake会自动处理)
FILES_${PN} += "${libdir}/libprotobuf*.so* ${bindir}/protoc"
FILES_${PN}-dev += "${includedir}/google ${libdir}/cmake"
FILES_${PN}-staticdev += "${libdir}/libprotobuf*.a"

3. 可选配置调整

  • 无需静态库时,将-Dprotobuf_BUILD_STATIC_LIBS=ON改为OFF
  • 需要Java/C#等语言绑定的话,添加对应依赖并在EXTRA_OECMAKE中开启选项(如-Dprotobuf_BUILD_JAVA=ON)
  • 针对硬件架构优化,可添加-Dprotobuf_OPTIMIZE_FOR_SIZE=ON等参数

4. 集成到Yocto构建

  • 确保自定义layer已添加到bblayers.conf:
    BBLAYERS += "${TOPDIR}/../layers/your-custom-layer"
    
  • 在local.conf中指定安装Protobuf组件:
    IMAGE_INSTALL:append = " protobuf protobuf-dev protobuf-staticdev"
    
  • 执行构建:bitbake your-image-name,Protobuf 3.19.6会被编译并安装到目标镜像中

内容的提问来源于stack exchange,提问作者S.Sathish Kumar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 19:42:56