Ubuntu下多架构依赖安装失败导致Rust交叉编译树莓派项目出错求助
大家好,我最近在做一个Rust开发的项目,需要交叉编译到树莓派4(目标架构是armv7-unknown-linux-gnueabihf),遇到了非常棘手的问题,折腾很久都没解决,想请教下大家。
问题背景
我这个项目依赖了v4l-rs库,它底层是基于C/C++的Video4Linux2库。Rust本身跨编译其实挺顺畅的,但只要涉及到C语言依赖就出问题了。
最初遇到的编译错误
一开始我安装了x86架构的依赖包:libv4l-dev libclang-11-dev gcc-arm-linux-gnueabihf,然后用armv7工具链编译,结果报错找不到头文件:
error: failed to run custom build command for `v4l2-sys-mit v0.2.0` Caused by: process didn't exit successfully: `/home/makerio/projects/wificar/target/release/build/v4l2-sys-mit-e6f39e3cdb722d62/build-script-build` (exit status: 101) --- stderr /usr/include/linux/videodev2.h:60:10: fatal error: 'sys/time.h' file not found /usr/include/linux/videodev2.h:60:10: fatal error: 'sys/time.h' file not found, err: true thread 'main' panicked at 'Failed to generate bindings: ()', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/v4l2-sys-mit-0.2.0/build.rs:10:10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
后来查了下,应该是因为我装的是x86版本的依赖,跨编译时需要对应armhf架构的库才行。
尝试解决但遇到新问题
我按照教程添加了armhf架构,写了个脚本安装armhf版本的依赖:
# add arch dpkg --add-architecture armhf # create the sources list sudo touch /etc/apt/sources.list.d/arm-cross-compile-sources.list # move the list to there sudo cp ./scripts/arm-cross-compile-sources.list /etc/apt/sources.list.d/arm-cross-compile-sources.list # dont use the existing sources sed "s/deb/deb [arch=amd64]/" /etc/apt/sources.list | sudo tee /etc/apt/sources.list sudo apt update # install the packages sudo apt install -y libv4l-dev:armhf libclang-11-dev:armhf gcc-arm-linux-gnueabihf
但执行apt install时出现了一堆依赖未满足的错误,很多包比如libc6:armhf、libgcc-s1:armhf都提示“not installable”,具体错误如下:
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:The following packages have unmet dependencies:
libasan5:armhf : Depends: libc6:armhf (>= 2.28) but it is not installable
Depends: libgcc-s1:armhf but it is not installable
libclang-common-11-dev:armhf : Depends: libc6:armhf (>= 2.17) but it is not installable
Depends: libgcc-s1:armhf (>= 4.3) but it is not installable
Depends: libstdc6:armhf (>= 4.1.1) but it is not installable
libclang1-11:armhf : Depends: libc6:armhf (>= 2.4) but it is not installable
Depends: libgcc-s1:armhf (>= 3.5) but it is not installable
Depends: libstdc6:armhf (>= 9) but it is not installable
libffi7:armhf : Depends: libc6:armhf (>= 2.7) but it is not installable
Depends: libgcc-s1:armhf (>= 3.5) but it is not installable
libgc1c2:armhf : Depends: libc6:armhf (>= 2.28) but it is not installable
Depends: libgcc-s1:armhf (>= 3.5) but it is not installable
Depends: libstdc6:armhf (>= 4.3.0) but it is not installable
libgcc-9-dev:armhf : Depends: libgcc-s1:armhf (>= 9.4.0-1ubuntu1~20.04.1) but it is not installable
Depends: libgomp1:armhf (>= 9.4.0-1ubuntu1~20.04.1) but it is not going to be installed
Depends: libatomic1:armhf (>= 9.4.0-1ubuntu1~20.04.1) but it is not going to be installed
Depends: libubsan1:armhf (>= 9.4.0-1ubuntu1~20.04.1) but it is not going to be installed
Recommends: libc6-dev:armhf (>= 2.13-0ubuntu6) but it is not going to be installed
libllvm11:armhf : Depends: libc6:armhf (>= 2.29) but it is not installable
Depends: libedit2:armhf (>= 2.11-20080614-0) but it is not going to be installed
Depends: libgcc-s1:armhf (>= 4.3) but it is not installable
Depends: libstdc6:armhf (>= 9) but it is not installable
Depends: libtinfo6:armhf (>= 6) but it is not going to be installed
Depends: zlib1g:armhf (>= 1:1.2.0) but it is not installable
libobjc4:armhf : Depends: libc6:armhf (>= 2.4) but it is not installable
Depends: libgcc-s1:armhf (>= 3.5) but it is not installable
libstdc++-9-dev:armhf : Depends: libstdc++6:armhf (>= 9.4.0-1ubuntu1~20.04.1) but it is not installable
Depends: libc6-dev:armhf (>= 2.13-0ubuntu6) but it is not going to be installed
libv4l-0:armhf : Depends: libc6:armhf (>= 2.27) but it is not installable
libv4l2rds0:armhf : Depends: libc6:armhf (>= 2.4) but it is not installable
libv4lconvert0:armhf : Depends: libc6:armhf (>= 2.27) but it is not installable
Depends: libjpeg8:armhf (>= 8c) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
现在的疑问
我现在完全搞不懂了:
- 提示的“not installable”到底是什么意思?为什么这些基础库都装不了?
- 另外确认下,
armv7-unknown-linux-gnueabihf确实是树莓派4的正确工具链吧?
补充信息:我是在GitHub Actions里做编译,用act本地测试;项目太大,没法直接在树莓派上编译。
备注:内容来源于stack exchange,提问作者makerio

