rust-by-example/11.Crates/using_library.rs
2023-12-11 18:40:53 +08:00

21 lines
644 B
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//!
//! 使用库文件
//!
//! 想要让包连接到一个库,需要使用 rustc 的 --extern 的参数来指定库名称,
//! 比如 `rustc using_library.rs --extern rary=library.rlib`
//! 通过参数指定的库会绑定通过指定的名字当做一个模块导入到当前做的作用域中。
//! 编译以后会生成一个 `using_library` 的二进制可执行文件。
//!
// Rust 2015版本之前需要明确的导入需要使用的外部库
// extern crate rary;
fn main() {
rary::public_function();
// 错误!`private_function` 是私有函数。
//rary::private_function();
rary::indirect_access();
}