Opencv-rust: Fails to load .so at runtime

I opened a detailed issue in the repository, but just in case… I created a Docker image from rust:1.57.0-bullseye and compiled OpenCV with the contrib and non-free modules. I can see the .so files in /usr/local/lib, and based on the output from cargo test -vv I can see that /usr/local/lib is being included in the link paths. However, when I try to run my tests (which is where OpenCV is used), I get this error:

Finished test [unoptimized + debuginfo] target(s) in 1m 59s
     Running `/usr/src/app/rust/target/debug/deps/backend-e32510369b055f2d`
/usr/src/app/rust/target/debug/deps/backend-e32510369b055f2d: error while loading shared libraries: cannot open shared object file: No such file or directory
error: test failed, to rerun pass '--bin backend'

Is there something more I need to do for Rust to be able to find the library? I tried with OPENCV_LINK_PATHS=+/usr/local/lib as well, but the result was the same. I’ve uploaded the full RUST_BACKTRACE=1 cargo -vv test output separately. I’ll repeat the dev Dockerfile here (note that I’m mounting my source as a volume):

FROM rust:1.57.0-bullseye


RUN apt-get update -qq && apt-get install -qqy wget software-properties-common libclang-dev cmake make unzip

RUN bash -c "$(wget -O -"

RUN cd /tmp && \
    wget -O${OPENCV_VERSION}.zip && \
    wget -O${OPENCV_VERSION}.zip && \
    unzip && \
    unzip && \
    mkdir build && \
    cd build && \
    cmake --build . -j $(nproc) && \
    make install

RUN ln -s /usr/lib/llvm-13/bin/llvm-config /usr/local/bin/llvm-config

Fixed by setting LD_LIBRARY_PATH programmatically. Now I can get back to debugging my own problematic code!