#failed when using ffi

4 messages · Page 1 of 1 (latest)

south marsh
#

hey guys, I am trying ffi, follow this tutorial https://doc.rust-lang.org/nomicon/ffi.html
this is my build.rs in the root of project

fn main() {
    println!("cargo:rustc-link-lib=dylib=stdc++"); // This line may be unnecessary for some environments.

    // I have tried this, but not working
    // println!("cargo:rustc-link-search=/home/steiner/workspace/ffi-examples/snappy-c/");

    println!("cargo:rustc-link-search=./snappy-c/");
}

and I clone the snappy-c, ane make it, ln -s libsnappyc.so.1 libsnappy.so
the building is ok, but the running failed, with

target/debug/ffi-examples: error while loading shared libraries: libsnappy.so: cannot open shared object file: No such file or directory

and the ldd shows

steiner@debian-workstation ~/w/ffi-examples (master) [127]> ldd target/debug/ffi-examples
        linux-vdso.so.1 (0x00007f2457524000)
        libsnappy.so => not found
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2457474000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2457280000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f2457526000)

how can I solve it ??

compact harbor
#

Not an expert but I built the shared lib and copied the libs over with below cmds, works for me:

cmake -S snappy -B snappy-build-shared \
  -DBUILD_SHARED_LIBS=ON \
  -DSNAPPY_BUILD_TESTS=OFF \
  -DSNAPPY_BUILD_BENCHMARKS=OFF

cmake --build snappy-build-shared
mkdir -p snappy-c
cp snappy-build-shared/libsnappy.so* snappy-c/
idle owl
#

When linking a dynamic library, you would install it in the same place on your dev machine as it will be when deployed, i.e. systemwide via your package manager