Is there a way to compile a crate Rust and its dependencies into an .a (or .rlib) file that can then be used when compiling another .rs file with "rustc" ?
For example, here is the Cargo.toml file used to create a static library enabling all postgres functions to be used (without going through cargo):
[lib]
name = "my_postgres_lib"
crate-type = ["staticlib"]
[dependencies]
postgres = "0.19"
Here are the contents of the src/lib.rs file:
extern crate postgres;
pub use postgres::*;
And here is the main.rs file to be compiled without going through cargo (with ‘rustc main.rs -L ../my_postgres_lib/target/release -l my_postgres_lib’):
extern crate my_postgres_lib;
use my_postgres_lib::{Client, NoTls};
fn main() {
match Client::connect("host=localhost user=postgres", NoTls) {
Ok(mut client) => {
println!("Success");
}
Err(e) => {
eprintln!("Error : {}", e);
}
}
}
Unfortunately, the rustc command given above always gives me this kind of response:
error[E0463]: can't find crate for `postgres` which `my_postgres_lib` depends on
--> main.rs:8:1
|
8 | extern crate my_postgres_lib;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0463`.