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

Yocto Recipe中通过postinstall解决交叉编译ARM二进制执行兼容问题

Let’s walk through each of your questions with clear, actionable solutions tailored to your Yocto and Makefile setup:

1. Modified Makefile (Removing the json Target)

The json target relies on your ARM-built analyzer binary, which can’t run on an x86 host—so we’ll strip out all related code. Here’s the cleaned-up Makefile:

TARGETDIR=../rel/$(PLATFORM)
ANALYZER=$(TARGETDIR)/analyzer
TARGETS=$(ANALYZER)

all: $(TARGETS)

$(ANALYZER): analyzer.c pgn.c analyzer.h pgn.h ../common/common.c ../common/common.h Makefile
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $(ANALYZER) -I../common pgn.c analyzer.c ../common/common.c $(LDLIBS$(LDLIBS-$(@)))

We removed:

  • The JSONFILE and XMLFILE variables (only used by the json target)
  • The entire json target rule

2. Do I need to add DEPENDS = "libxslt libxml2"?

No, you don’t need this in DEPENDS—here’s why:

  • DEPENDS specifies build-time dependencies (libraries/tools needed to compile your code). Your analyzer binary doesn’t link against libxml2 or libxslt, so these aren’t required for compilation.
  • Instead, you need to add libxslt to RDEPENDS_${PN} (runtime dependencies), since the target device will need xsltproc (provided by libxslt) to convert the XML to JSON during installation.

3. Do I need to add RDEPENDS_${PN} = "bash"?

Only if your post-install script uses bash-specific syntax.
Yocto’s default shell on target devices is a POSIX-compliant /bin/sh (usually busybox sh or dash). If your script only uses standard shell features (simple commands, pipes, redirection), bash isn’t needed. Reserve this dependency only if you use bash-exclusive tools like arrays, [[ ]] conditionals, or shopt settings.

4. Writing the Target Device Post-Install Script

We’ll use Yocto’s pkg_postinst_${PN} hook, which runs on the target device when the package is installed. First, update your Recipe to install the XSLT script and define the post-install logic:

SUMMARY = "CANBOAT"
SECTION = "base"
LICENSE = "GPLv3"
LIC_FILES_CHKSUM = "file://GPL;md5=05507c6da2404b0e88fe5a152fd12540"
S = "${WORKDIR}/git"
SRC_URI = "git://github.com/canboat/canboat.git;branch=${SRCBRANCH}"
SRCBRANCH = "master"
SRCREV = "93b2ebfb334d7a9750b6947d3a4af9b091be2432"
EXTRA_OEMAKE = "'CC=${CC}' 'AR=${AR}'"

# Runtime dependency: target needs xsltproc for XML->JSON conversion
RDEPENDS_${PN} += "libxslt"

do_compile() {
	oe_runmake
}

do_install() {
	oe_runmake install
	# Install the XSLT script to a shared directory on the target
	install -d ${D}${datadir}/canboat/
	install -m 0644 ${S}/pgns2json.xslt ${D}${datadir}/canboat/
}

# This script executes on the target device during package installation
pkg_postinst_${PN}() {
	#!/bin/sh
	set -e

	# Define paths on the target (adjust analyzer path if your make install uses a different location)
	ANALYZER="/usr/bin/analyzer"
	XSLT_SCRIPT="/usr/share/canboat/pgns2json.xslt"
	TEMP_XML="/tmp/pgns.xml"
	FINAL_JSON="/usr/share/canboat/pgns.json"

	# Generate XML, convert to JSON, clean up
	${ANALYZER} -explain-xml > ${TEMP_XML}
	xsltproc ${XSLT_SCRIPT} ${TEMP_XML} > ${FINAL_JSON}
	rm -f ${TEMP_XML}

	# Set correct permissions for the JSON file
	chmod 0644 ${FINAL_JSON}
}

Key details:

  • do_install adds the pgns2json.xslt script to the target’s shared directory so the post-install script can access it.
  • pkg_postinst_${PN} runs on the target, using the native ARM analyzer binary to generate XML, then xsltproc to convert it to JSON. We use a temporary XML file to avoid clutter.
  • Double-check the ANALYZER path: if your make install puts the binary somewhere other than /usr/bin/, update this accordingly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 07:13:43