]>
Commit | Line | Data |
---|---|---|
1b1a35ee | 1 | # Creating a Library |
2c00a5a8 XL |
2 | |
3 | Let's create a library, and then see how to link it to another crate. | |
4 | ||
48663c56 | 5 | ```rust,ignore |
2c00a5a8 XL |
6 | pub fn public_function() { |
7 | println!("called rary's `public_function()`"); | |
8 | } | |
9 | ||
10 | fn private_function() { | |
11 | println!("called rary's `private_function()`"); | |
12 | } | |
13 | ||
14 | pub fn indirect_access() { | |
15 | print!("called rary's `indirect_access()`, that\n> "); | |
16 | ||
17 | private_function(); | |
18 | } | |
19 | ``` | |
20 | ||
416331ca | 21 | ```shell |
2c00a5a8 XL |
22 | $ rustc --crate-type=lib rary.rs |
23 | $ ls lib* | |
24 | library.rlib | |
25 | ``` | |
26 | ||
27 | Libraries get prefixed with "lib", and by default they get named after their | |
f9f354fc XL |
28 | crate file, but this default name can be overridden by passing |
29 | the `--crate-name` option to `rustc` or by using the [`crate_name` | |
2c00a5a8 XL |
30 | attribute][crate-name]. |
31 | ||
dc9dc135 | 32 | [crate-name]: ../attribute/crate.md |