#How does rustc (not cargo) finds the linking library file's name?
6 messages · Page 1 of 1 (latest)
I just tested it with rlib and here are my observations:
Code:
// lib.rs
#![crate_type = "rlib"]
#![crate_name = "my_lib"]
pub fn run() {
println!("Working!")
}
// main.rs
extern crate my_lib;
fn main() {
my_lib::run();
}
Commands I used to compile (on windows):
C:/Users/Me/Desktop/Rust/Test> rustc lib.rs
C:/Users/Me/Desktop/Rust/Test> rustc main.rs -L.
Observations:
- Compiling the
lib.rsfile gave me a new file namedlibmy_lib.rlib - If I rename this file to
libsomething.rlib, and inmain.rs, I useextern crate something, the compilation fails. - If I rename this file to
libsomething.rlib, and leave everything else the same, the compilation still fails.
Basically if I keep the compiler generated name, and I have used the crate_name attribute while compiling the library, the compilation is successful, otherwise it would give compilation error.
The extern crate line is what gives the name
Note that in modern rustc the extern crate isn't needed if you use the extern argument to manually pass it to rustc
Both of the file and the crate in the file
but if I change libmy_lib.rlib to libsomething.rlib, and extern my_lib to extern something, the compilation breaks.