1

I can compile and run my Rust project without any problems using cargo run --release. As a second step I simply want to create the binary using cargo build --release and then executing it by running ./target/release/crate_name (it is also explained here). Executing the binary results in the behaviour that some shared libraries are not found. This is my 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"

And this is the error message: error while loading shared libraries: libonnxruntime.so.1.8.1: cannot open shared object file: No such file or directory.

So my question, is cargo run --release linking some libraries implicitly? I mean the library exisits somewhere in the target/release/build/... path. I did not found out anything by providing the --verbose flag.

EDIT ls target/release:

build           
deps            
examples        
incremental     
onnx-test onnx-test.d
nerdizzle
  • 424
  • 4
  • 17
  • Probably a case of adjusting `LD_LIBRARY_PATH` for you. – tadman May 03 '23 at 15:21
  • Provide the output of `ls target/release` – PitaJ May 03 '23 at 15:23
  • @tadman I thought about that, but the libraries are not in one folder, they are all in subfolders and I don't want to adjust the path for each library? – nerdizzle May 03 '23 at 15:56
  • @PitaJ I added the output as edit in the question. – nerdizzle May 03 '23 at 15:56
  • 2
    We might have to reproduce this error on our own machine. Please [edit] your question to provide a full [MRE], including everything necessary to create the error on our own machines. Meaning: a `main.rs`, the `Cargo.toml`(which you already provided), and instructions on how you installed the library in question, in case you installed it manually somewhere. Also, please try to reduce the problem down to a minimal example, including only the dependencies in your `Cargo.toml` that are necessary. – Finomnis May 03 '23 at 16:02
  • 2
    This is the problem that [`cargo install`](https://doc.rust-lang.org/cargo/commands/cargo-install.html) solves. When in the `target` directory they're not fully installed, so there may be some overhead in getting it to run from there if avoiding `cargo run`. – tadman May 03 '23 at 16:34

1 Answers1

0

Yes. The behavior is documented.

Cargo also sets the dynamic library path when compiling and running binaries with commands like cargo run and cargo test. This helps with locating shared libraries that are part of the build process.

And here is the current implementation.

Weihang Lo
  • 59
  • 2
  • 5