ARM平台交叉编译systemd遇mount依赖问题求助
Hey there! Let's work through this cross-compilation headache with systemd on ARM—I've tangled with similar dependency issues before, so here's what I recommend:
First, you'll want to organize your cross-compiled libmount into a sysroot directory that mimics the target ARM system's filesystem structure. This helps Meson and other tools find dependencies intuitively. Let's say you use /opt/arm-cross-sysroot/ as your sysroot:
- Copy libmount's header files (everything from util-linux's
include/dir related to mount) to/opt/arm-cross-sysroot/usr/include/ - Drop the compiled library files (
.so,.a, and versioned.so.x.x.xfiles) into/opt/arm-cross-sysroot/usr/lib/ - If you generated a
libmount.pcpkg-config file during util-linux compilation, place it in/opt/arm-cross-sysroot/usr/lib/pkgconfig/
Your cross-compilation file needs to explicitly point Meson to this sysroot and the tools that understand your ARM target. Here's an updated snippet for your cross file (e.g., arm-cross-file.txt):
[constants] sysroot = '/opt/arm-cross-sysroot' [binaries] c = 'arm-linux-gnueabihf-gcc' # Replace with your actual ARM compiler cpp = 'arm-linux-gnueabihf-g++' ar = 'arm-linux-gnueabihf-ar' strip = 'arm-linux-gnueabihf-strip' pkgconfig = 'arm-linux-gnueabihf-pkg-config' [properties] sysroot = sysroot pkg_config_path = '@0@/usr/lib/pkgconfig'.format(sysroot)
When running Meson setup, you need to force it to use the external libmount (systemd sometimes defaults to an internal implementation) and clarify the mount binary path for the target system:
meson setup build --cross-file arm-cross-file.txt -Dlibmount=enabled -Dmount-path=/usr/bin/mount
Note: The mount-path option only sets where the mount binary lives on the target device—it doesn't help Meson find the libmount library itself, which is why your earlier attempts didn't work.
If Meson still can't locate libmount, you can manually specify the paths during setup:
meson setup build --cross-file arm-cross-file.txt \ -Dlibmount-include-dir=/opt/arm-cross-sysroot/usr/include \ -Dlibmount-lib-dir=/opt/arm-cross-sysroot/usr/lib \ -Dmount-path=/usr/bin/mount
You can also run meson configure build after setup to check if the libmount-related options are correctly populated—this helps catch typos or path mistakes.
If cross-compiling from scratch feels too tedious, here are simpler routes:
- Use a Prebuilt Root Filesystem: Most ARM-focused distros (Debian ARM, Ubuntu Server ARM, Raspberry Pi OS) include prebuilt systemd packages. Download a rootfs matching your target ARM architecture (armhf/arm64), extract it to your device, and you're good to go—no compilation needed.
- Distro Cross-Build Tools: Tools like
debootstrap(for Debian/Ubuntu) let you cross-build a full rootfs with systemd. For example:
You can then usedebootstrap --arch=armhf --foreign bullseye /opt/arm-rootfs http://deb.debian.org/debianqemu-arm-staticto chroot into the rootfs on your x86 machine and tweak packages as needed. - Buildroot: This embedded Linux build system simplifies the entire process. Just enable systemd in Buildroot's
menuconfig, set your target ARM architecture, and Buildroot handles all dependencies, cross-compilation, and rootfs assembly automatically.
内容的提问来源于stack exchange,提问作者Dalbenn

