scipopt/russcip

from-source gives: `libscip.so.9.0: cannot open shared object file: No such file or directory`

Opened this issue ยท 6 comments

Using the new feature from-source, available since 0.3.3, I'm unable to run the built binary. Here's my MRE:

Dockerfile:

FROM rust:1.77
WORKDIR /work
RUN apt-get update && apt-get install -y cmake clang
RUN wget https://github.com/scipopt/russcip/archive/refs/tags/v0.3.3.tar.gz \
    && tar -xzvf v0.3.3.tar.gz \
    && mv russcip-0.3.3 /russcip
WORKDIR /russcip
RUN cargo build --release -F from-source --example create_and_solve
CMD ["./target/release/examples/create_and_solve"]

Build:

docker build .

Run / error:

docker run -it --rm russcip-test:latest
./target/release/examples/create_and_solve: error while loading shared libraries: libscip.so.9.0: cannot open shared object file: No such file or directory

Same here. With cargo run it works, similar to the bundled feature.

Seems like the same difficulties with dynamic linking. Is it possible to add static linking now with from-source-building?

Sorry guys for the false hope ๐Ÿ˜„ but at least now the build process can be controlled from rust, so it's a small step in the right direction. Unfortunately, only setting SHARED=false is not enough, I will be iterating on it in this PR scipopt/scip-sys#15

No worries, I'm just happy to see you working on it ๐Ÿ˜€

I think I found a nice solution that doesn't requires much work. I updated scip-sys (v0.1.12, and a corresponding russcip version 0.3.4 to use it) to also say where it found libscip. It sets the environment variable DEP_SCIP_LIBDIR. You could use that information to set the rpath of the binary you're building by adding something like this to your build script

fn main() {
    let libscip_dir = std::env::var("DEP_SCIP_LIBDIR").unwrap();
    println!("cargo:rustc-link-arg=-Wl,-rpath,{}", libscip_dir);
}

I think you might also need to add scip-sys to the dependencies of your crate not just russcip.
It's not probably the nicest solution since it requires a bit of effort from the downstream user of scip-sys but should do the job. @jacobsvante @mwien What do you think?

I think for the bundled feature with pre-built binary that cannot be statically linked it is likely the only way and a nice-to-have option ๐Ÿ‘

Will test it out in the coming days.

I'm still gonna look into static linking because I probably need it for a project. Gonna write if I can make it work, should be doable in principle ๐Ÿค”

Thanks for your work โค๏ธ

Haven't had the chance to try yet but will soon.
Have you tried building and linking scip statically?