Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell rustc (through cargo) where to find my dll import library

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?

like image 531
Benjamin Lindley Avatar asked Aug 02 '15 07:08

Benjamin Lindley


1 Answers

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.

like image 200
Vladimir Matveev Avatar answered Oct 20 '22 20:10

Vladimir Matveev