I have a shared library that I\'d like to dynamically link into several separate binary Cargo applications. I include its location in the linker using the -- -L /path
Adding to what Shepmaster said (apparently I don't have enough reputation to comment): I'm not sure when this feature was added, but as of at least Rust 1.20, you can achieve the same effect by setting the environment variable RUSTFLAGS
:
$ RUSTFLAGS="-C link-args=-Wl,-rpath,/the/lib/path" cargo build
This can be more convenient than the cargo rustc
option if, for instance, you're using build scripts that just invoke cargo build
.