为什么“cargo run”可以工作,但直接运行可执行文件却无法加载共享库?

问题描述 投票:0回答:1

我可以使用

cargo run --release
毫无问题地编译和运行我的 Rust 项目。第二步,我只想使用
cargo build --release
创建二进制文件,然后通过运行
./target/release/crate_name
来执行它(也有解释 here)。执行二进制文件会导致找不到某些共享库的行为。这是我的
Cargo.toml
:

[package]
name = "onnx-test"
version = "0.1.0"
edition = "2023"

[dependencies]
actix-web = "4"
futures = "0.3.26"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
onnxruntime = "0.0.14"
image = "0.24.5"
imageproc = "0.23.0"
rusttype = "0.9.3"
lazy_static = "1.4.0"
base64 = "0.21.0"
actix-cors = "0.6.4"
derive_more = "0.99.17"
actix-web-validator = "5.0.1"
validator = { version = "0.16", features = ["derive"] }
regex = "1.5.6"

这是错误消息:

error while loading shared libraries: libonnxruntime.so.1.8.1: cannot open shared object file: No such file or directory

所以我的问题是,

cargo run --release
隐式链接一些库吗?我的意思是该库存在于
target/release/build/...
路径中的某个位置。我没有通过提供
--verbose
标志发现任何信息。

以下是

target/release
的内容:

build/
deps/
examples/
incremental/
onnx-test
onnx-test.d
rust rust-cargo onnx onnxruntime
1个回答
1
投票

是的。该行为已记录在案

Cargo 还会在使用

cargo run
cargo test
等命令编译和运行二进制文件时设置动态库路径。这有助于定位构建过程中的共享库。

并且这是当前的实现

© www.soinside.com 2019 - 2024. All rights reserved.