]> git.proxmox.com Git - rustc.git/blame - src/doc/rust-by-example/src/crates/link.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / doc / rust-by-example / src / crates / link.md
CommitLineData
2c00a5a8
XL
1# `extern crate`
2
3To link a crate to this new library, the `extern crate` declaration must be
4used. This will not only link the library, but also import all its items under
5a module named the same as the library. The visibility rules that apply to
6modules also apply to libraries.
7
8```rust,ignore
9// Link to `library`, import items under the `rary` module
10extern crate rary;
11
12fn main() {
13 rary::public_function();
14
15 // Error! `private_function` is private
16 //rary::private_function();
17
18 rary::indirect_access();
19}
20```
21
416331ca 22```txt
2c00a5a8
XL
23# Where library.rlib is the path to the compiled library, assumed that it's
24# in the same directory here:
25$ rustc executable.rs --extern rary=library.rlib && ./executable
26called rary's `public_function()`
27called rary's `indirect_access()`, that
28> called rary's `private_function()`
29```