I'm producing a dll with mingw to be used by rust. I know I can place my libxxx.a
file in the "Rust\bin\rustlib\x86_64-pc-windows-gnu\lib"
directory, and that's what I'm doing now. But I'd rather keep it in my project's directory. How do I get Cargo to tell rustc where to find it?
First, you can use cargo rustc
to pass the -L dir
parameters to rustc directly:
cargo rustc -- -L lib
if your library is located in lib
subdirectory.
Another, probably more convenient, way is to use a build script to pass library directory to rustc automatically. It then will be used with other cargo commands as well, like run
, test
, etc. If you store the following code to build.rs
:
fn main() {
println!("cargo:rustc-link-lib=native=foo");
println!("cargo:rustc-link-search=native=lib");
}
(assuming your library is called libfoo.a
)
and then add build
key to [package]
section in Cargo.toml:
[package]
...
build = "build.rs"
then it should find your library automatically upon every build command.
Note that the build script is also a nice place to actually build your library. Cargo documentation contains examples and links on that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With