]> git.lizzy.rs Git - rust.git/blob - src/doc/trpl/advanced-linking.md
Rename 'link-args' to 'advanced-linking', add intro
[rust.git] / src / doc / trpl / advanced-linking.md
1 % Advanced Linking
2
3 The common cases of linking with Rust have been covered earlier in this book,
4 but supporting the range of linking possibilities made available by other
5 languages is important for Rust to achieve seamless interaction with native
6 libraries.
7
8 # Link args
9
10 There is one other way to tell `rustc` how to customize linking, and that is via
11 the `link_args` attribute. This attribute is applied to `extern` blocks and
12 specifies raw flags which need to get passed to the linker when producing an
13 artifact. An example usage would be:
14
15 ``` no_run
16 #![feature(link_args)]
17
18 #[link_args = "-foo -bar -baz"]
19 extern {}
20 # fn main() {}
21 ```
22
23 Note that this feature is currently hidden behind the `feature(link_args)` gate
24 because this is not a sanctioned way of performing linking. Right now `rustc`
25 shells out to the system linker, so it makes sense to provide extra command line
26 arguments, but this will not always be the case. In the future `rustc` may use
27 LLVM directly to link native libraries, in which case `link_args` will have no
28 meaning.
29
30 It is highly recommended to *not* use this attribute, and rather use the more
31 formal `#[link(...)]` attribute on `extern` blocks instead.
32