如何将rust项目与armv7的opencv包交叉编译



我有一个简单的rust应用程序,它在Ubuntu主机上编译时没有出错。Cargo.toml看起来是这样的:

[package]
name = "openvc-test"
version = "0.1.0"
edition = "2021"
[dependencies]
opencv = "0.66"

然后,我尝试为armv7未知的linux gnueabihf交叉编译这个项目,这样我就可以在树莓上运行二进制文件了。我为此使用了交叉工具。跨项目的常见问题解答提供了一些关于如何处理外部库的信息。因此,我尝试在docker映像上安装libopencv-dev:armhf,就像常见问题解答中的示例一样。然而,我得到以下错误:

The following packages have unmet dependencies:
libopencv-dev:armhf : Depends: libopencv3.2-java:armhf (= 3.2.0+dfsg-6) but it is not installable
Recommends: opencv-data:armhf but it is not installable

我还尝试使用常见问题解答中描述的Debian存储库。错误是相同的。

有人知道如何解决这个问题吗?或者,我可以尝试另一种交叉编译rust项目的方法吗?

在树莓上编译不起作用,编译被困在opencv包中。我想是因为rapsberry的性能有限吗?

在docker容器中安装预编译的opencv包是不起作用的(仍然不知道为什么(,但交叉编译正确的opencv版本是起作用的。请参阅以下docker文件:

ARG CROSS_BASE_IMAGE
FROM $CROSS_BASE_IMAGE
# requirements of bindgen, see https://rust-lang.github.io/rust-bindgen/requirements.html
RUN DEBIAN_FRONTEND=noninteractive apt install -y llvm-dev libclang-dev clang 
# cross compile opencv, see https://docs.opencv.org/4.x/d0/d76/tutorial_arm_crosscompile_with_cmake.html
RUN DEBIAN_FRONTEND=noninteractive apt install -y gcc-arm-linux-gnueabihf git build-essential cmake
RUN git clone --depth 1 --branch '4.5.1' https://github.com/opencv/opencv.git && 
cd opencv/platforms/linux && 
mkdir build && 
cd build && 
cmake -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../.. && 
make && 
make install
ENV CMAKE_PREFIX_PATH="/opencv/platforms/linux/build/install"

Cross.toml中,您只需指定dockerfile的路径,例如:

[target.armv7-unknown-linux-gnueabihf]
dockerfile = "./Dockerfile"

交叉编译Rust项目:

cross build --target armv7-unknown-linux-gnueabihf

docker容器的初始设置需要相当长的时间。

最新更新