]>
Commit | Line | Data |
---|---|---|
2c00a5a8 XL |
1 | # `extern crate` |
2 | ||
3 | To link a crate to this new library, the `extern crate` declaration must be | |
4 | used. This will not only link the library, but also import all its items under | |
5 | a module named the same as the library. The visibility rules that apply to | |
6 | modules also apply to libraries. | |
7 | ||
8 | ```rust,ignore | |
9 | // Link to `library`, import items under the `rary` module | |
10 | extern crate rary; | |
11 | ||
12 | fn 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 | |
26 | called rary's `public_function()` | |
27 | called rary's `indirect_access()`, that | |
28 | > called rary's `private_function()` | |
29 | ``` |