Hello, everyone.
Recently I was writing an assembler and trying to assemble it into a statically linked library. I would like to ask how to ask RUSTC compiler or CARGO to link to a static link library? This will allow me to use my assembler in RUST.
Does this SO answer by shepmaster help you get started?
you need a build script in order to link to native libraries. for example, suppose the library is named libfoo.a
, your build script should look like this:
// build.rs
fn main() {
// link to static library `foo`
println!("cargo:rustc-link-lib=static=foo");
// if the library file is not in a standard directory, you also need
println!("cargo:rustc-link-search=native=/path/to/directory/of/the/library");
}
see the cargo book:
https://doc.rust-lang.org/stable/cargo/reference/build-scripts.html#rustc-link-lib
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.