Description
Hi,
Consider this minimal example project:
https://github.com/vext01/rust_link_test
The project has a dependency written in C which is built by the build.rs
.
For the examples or tests to work, the shared object for the C code needs to be in the linker path:
Running target/debug/deps/link_test-8d72230c7bcf790a
/home/vext01/research/link_test/target/debug/deps/link_test-8d72230c7bcf790a: error while loading shared libraries: libcstuff.so: cannot open shared object file: No such file or directory
If I set LD_LIBRARY_PATH
to c_lib
then everything works. The standard way to work around having to set the LD_LIBRARY_PATH
is to encode an rpath into the consuming binary (in this case the example or test binary).
Whilst the example be fixed using, e.g.:
#![link_args="-Wl,-rpath /home/vext01/research/link_test/c_lib"]
At the top of the file, the same doesn't appear to be true of tests.
Another thing that bothers me about using link_args
is that it assumes that the path is known, but typically that's a detail that only the build script will know.
Cargo build scripts already have cargo:rustc-link-lib
which allows this kind of thing to add linkage to a given library:
println!("cargo:rustc-link-lib=cstuff");
Why not have a more general interface whereby arbitrary linker flags can be passed?
Hope this make sense.