I am generating rust bindings for a c .so library using bindgen inside a build script
My build.rs
file
let curr_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
println!(
"cargo:rustc-link-search=native={}",
curr_dir
);
println!("cargo:rustc-link-lib=dylib=my_library");
let bindings = bindgen::Builder::default()
.header("library_header.h")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
bindings
.write_to_file(out_path.join("src/bindings.rs"))
.expect("Couldn't write bindings!");
The bindings are generated correctly but when I am trying to use the library by running cargo test
I am getting error
/target/debug/deps/rust-binary: error while loading shared libraries: my_library.so: cannot open shared object file: No such file or directory
I have created an env varible also export LD_LIBRARY_PATH= /path/to/my_library/
as suggested by @jofas
Weirdly when I place my .so file inside /usr/lib
I am able to access the library functions. I am new to rust and ffi and I know I am doing something stupid. Can someone please help