Meson交叉编译依赖

Meson cross compiling dependencies

你好,我正在尝试为 arm 交叉编译 systemd,但我卡在了 'mount' 交叉依赖上。

我设法从 util-linux 交叉编译 libmount,但无法确定将它放在哪里或如何指定介子应该在哪里寻找它。

有一个 'mount-path' 选项,但即使在提供它时它仍然说:

Meson encountered an error in file meson.build, line 797, column 0:                                                    
Cross dependency 'mount' not found

我的交叉编译文件是这样的:

[binaries]                   
c = '/usr/bin/arm-linux-gnueabi-gcc'                       
cpp = '/usr/bin/arm-linux-gnueabi-g++'                     
ar = '/usr/arm-linux-gnueabi/bin/ar'                       
strip = '/usr/arm-linux-gnueabi/bin/strip'                 
pkgconfig = '/usr/bin/arm-linux-gnueabi-pkg-config'        

[host_machine]               
system = 'linux'             
cpu_family = 'arm'           
cpu = 'cortex-m4'            
endian = 'little'            

[build_machine]              
system = 'linux'             
cpu_family = 'x86_64'        
cpu = 'i686'                 
endian = 'little' 

顺便说一句,如果您知道另一种在没有这种可笑的(恕我直言)设置的情况下获得 systemd on arm 的方法,那就太好了。

谢谢。

Meson 使用 pkg-config 工具来查找依赖项。此工具使用 PKG_CONFIG_PATH 环境变量搜索所谓的 包配置文件 。 可以检查一下没有mount in:

$ pkg-config --list-all

这自然是因为你刚刚编译但是没有提供package config文件mount.pc被发现。检查 libmount 源,它应该包含安装过程使用的 mount.pc.in。在交叉编译的情况下,需要根据guide手动变成mount.pc。

创建包配置文件后,您应该能够成功 运行:

$ pkg-config --validate mount

您还可以检查变量的有效性:

$ pkg-config --cflags mount
-I/home/<>/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/libmount -I/home/<>/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/blkid -I/home/<>/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/uuid

$ pkg-config --libs mount  
-lmount

顺便说一句,这是我得到的 mount.pc 的内容:

prefix=/usr
exec_prefix=/usr
libdir=/usr/lib
includedir=/usr/include

Name: mount
Description: mount library
Version: 2.29.1
Requires.private: blkid
Cflags: -I${includedir}/libmount
Libs: -L${libdir} -lmount

Btw if you know about another way to get systemd on arm without this ridiculous(IMHO) setup it would be nice.

systemd 切换到 meson,所以现在这是唯一的方法,除非你想用 autotools 构建旧版本。

但想得更广泛,您还可以看看 yocto,它侧重于简化获取交叉编译的 linux 发行版。


更新

正如@Yasushi Shoji 正确指出的那样,对于交叉编译的情况,应该使用 PKG_CONFIG_LIBDIR,因为它可以防止 undesired/wrong 使用本地系统包,检查 this.