Where should I place a static library so I can link it with a Rust program?

前端 未结 2 2056
青春惊慌失措
青春惊慌失措 2020-12-14 09:18

I do not know how to link a C library to Rust. Here\'s what I have done:

My lib.rs file contains

#[link(name = \"test\")]
extern {
<         


        
2条回答
  •  借酒劲吻你
    2020-12-14 10:04

    I just found a solution (two) but I do not know if it's the best way:

    1- way

    build.rs file

    extern crate gcc;
    
    fn main() {
    
        println!("cargo:rustc-link-search=native=/home/path/to/rust/proyect/folder/contain/file.a");
        println!("cargo:rustc-link-lib=static=test");
    }
    

    Cargo.toml

    //..
    build = "build.rs"
    //..
    

    2- way

    Cargo.toml

    //..
    rustc-link-search = ["./src/lib"]
    rustc-link-lib = ["test"]
    root = "/home/path/to/rust/proyect/"
    //..
    

    ["./src/lib"] -> place to lib.a refence to root

提交回复
热议问题