]> git.proxmox.com Git - rustc.git/blame - src/doc/unstable-book/src/language-features/link-args.md
New upstream version 1.52.1+dfsg1
[rustc.git] / src / doc / unstable-book / src / language-features / link-args.md
CommitLineData
8bb4bdeb
XL
1# `link_args`
2
3The tracking issue for this feature is: [#29596]
4
5[#29596]: https://github.com/rust-lang/rust/issues/29596
6
7------------------------
8
9You can tell `rustc` how to customize linking, and that is via the `link_args`
10attribute. This attribute is applied to `extern` blocks and specifies raw flags
11which need to get passed to the linker when producing an artifact. An example
12usage would be:
13
14```rust,no_run
15#![feature(link_args)]
16
17#[link_args = "-foo -bar -baz"]
5869c6ff 18extern "C" {}
8bb4bdeb
XL
19# fn main() {}
20```
21
22Note that this feature is currently hidden behind the `feature(link_args)` gate
23because this is not a sanctioned way of performing linking. Right now `rustc`
24shells out to the system linker (`gcc` on most systems, `link.exe` on MSVC), so
25it makes sense to provide extra command line arguments, but this will not
26always be the case. In the future `rustc` may use LLVM directly to link native
27libraries, in which case `link_args` will have no meaning. You can achieve the
28same effect as the `link_args` attribute with the `-C link-args` argument to
29`rustc`.
30
31It is highly recommended to *not* use this attribute, and rather use the more
32formal `#[link(...)]` attribute on `extern` blocks instead.