How to statically link to an existing rlib?

2019-07-26 14:47发布

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.

标签: rust
0条回答
登录 后发表回答