1
1
# Linkage
2
2
3
- The Rust compiler supports various methods to link crates together both
3
+ > Note: This section is described more in terms of the compiler than of
4
+ > the language.
5
+
6
+ The compiler supports various methods to link crates together both
4
7
statically and dynamically. This section will explore the various methods to
5
- link Rust crates together, and more information about native libraries can be
8
+ link crates together, and more information about native libraries can be
6
9
found in the [ FFI section of the book] [ ffi ] .
7
10
8
11
[ ffi ] : ../book/ffi.html
@@ -35,7 +38,7 @@ be ignored in favor of only building the artifacts specified by command line.
35
38
36
39
* ` --crate-type=staticlib ` , ` #[crate_type = "staticlib"] ` - A static system
37
40
library will be produced. This is different from other library outputs in that
38
- the Rust compiler will never attempt to link to ` staticlib ` outputs. The
41
+ the compiler will never attempt to link to ` staticlib ` outputs. The
39
42
purpose of this output type is to create a static library containing all of
40
43
the local crate's code along with all upstream dependencies. The static
41
44
library is actually a ` *.a ` archive on linux and osx and a ` *.lib ` file on
@@ -44,15 +47,15 @@ be ignored in favor of only building the artifacts specified by command line.
44
47
dynamic dependencies on other Rust code.
45
48
46
49
* ` --crate-type=cdylib ` , ` #[crate_type = "cdylib"] ` - A dynamic system
47
- library will be produced. This is used when compiling Rust code as
50
+ library will be produced. This is used when compiling
48
51
a dynamic library to be loaded from another language. This output type will
49
52
create ` *.so ` files on Linux, ` *.dylib ` files on macOS, and ` *.dll ` files on
50
53
Windows.
51
54
52
55
* ` --crate-type=rlib ` , ` #[crate_type = "rlib"] ` - A "Rust library" file will be
53
56
produced. This is used as an intermediate artifact and can be thought of as a
54
57
"static Rust library". These ` rlib ` files, unlike ` staticlib ` files, are
55
- interpreted by the Rust compiler in future linkage. This essentially means
58
+ interpreted by the compiler in future linkage. This essentially means
56
59
that ` rustc ` will look for metadata in ` rlib ` files like it looks for metadata
57
60
in dynamic libraries. This form of output is used to produce statically linked
58
61
executables as well as ` staticlib ` outputs.
@@ -125,7 +128,7 @@ dependencies will be used:
125
128
126
129
In general, ` --crate-type=bin ` or ` --crate-type=lib ` should be sufficient for
127
130
all compilation needs, and the other options are just available if more
128
- fine-grained control is desired over the output format of a Rust crate.
131
+ fine-grained control is desired over the output format of a crate.
129
132
130
133
## Static and dynamic C runtimes
131
134
@@ -206,3 +209,7 @@ a statically linked binary on MSVC you would execute:
206
209
``` ignore,notrust
207
210
RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-pc-windows-msvc
208
211
```
212
+
213
+
214
+ [ configuration option ] : conditional-compilation.html
215
+ [ procedural macros ] : procedural-macros.html
0 commit comments