Reputation: 801
I have two independently created libsomelibrary.rlib
files at /path/to/deps/debug/
and /path/to/deps/release/
directories. I also have a project in the /path/to/myproject/
directory which needs to link statically to libsomelibrary.rlib
.
How can I specify in Cargo.toml (or elsewhere) the references to those .rlibs?
I have tried to add somelibrary
under [dependencies]
in Cargo.toml. using a build.rs to specify the search path and file name:
println!("cargo:rustc-link-lib=static=somelib");
println!("cargo:rustc-link-search=/path/to/deps/debug/");
then in Cargo.toml:
[package]
build = "build.rs"
links = "somelibrary"
but I still get linkage errors.
Upvotes: 7
Views: 4536
Reputation: 31
As far as I know, you gotta manually compile with rustc
rustc main.rs —-extern custom1=path/to/libcustom1.rlib —-extern custom2=path/to/libcustom2.rlib
With every library in the form of .rlib you add ‘—-extern’ for every single one of ‘em.
Refer to this
And to this
More than that, the man page for rustc will give you extra leg on more complex things like FFI
Upvotes: 3