Rust build.rs rustc-link-search

Cargo.toml

[package]
name = "static_link"
version = "0.1.0"
authors = ["develon <develon@qq.com>"]
edition = "2018"

build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

build.rs

fn main() {
    // println!("cargo:rustc-link-search={}", std::env::var("LIB_PATH").expect("请指定环境变量 LIB_PATH"));
    println!("cargo:rustc-link-search=clang/build/Debug");
}

main.rs

#[link(name = "libjt", kind = "static")]
extern {
    fn just_test();
}

fn main() {
    unsafe {
        just_test();
    }
}
posted @ 2022-08-29 17:06  develon  阅读(114)  评论(0编辑  收藏  举报