Skip to content

Commit 414d7cf

Browse files
committed
Update extern linking documentation.
1 parent 8e62a01 commit 414d7cf

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/doc/rustc/src/codegen-options/index.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ in software.
119119
## prefer-dynamic
120120

121121
By default, `rustc` prefers to statically link dependencies. This option will
122-
make it use dynamic linking instead.
122+
indicate that dynamic linking should be used if possible if both a static and
123+
dynamic versions of a library are available. There is an internal algorithm
124+
for determining whether or not it is possible to statically or dynamically
125+
link with a dependency. For example, `cdylib` crate types may only use static
126+
linkage.
123127

124128
## no-integrated-as
125129

src/doc/rustc/src/command-line-arguments.md

+23-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ For examples, `--cfg 'verbose'` or `--cfg 'feature="serde"'`. These correspond
1616
to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively.
1717

1818
## `-L`: add a directory to the library search path
19+
<a id="option-l-search-path"></a>
1920

20-
When looking for external crates or libraries, a directory passed to this flag
21-
will be searched.
21+
The `-L` flag adds a path to search for external crates and libraries.
2222

2323
The kind of search path can optionally be specified with the form `-L
2424
KIND=PATH` where `KIND` may be one of:
@@ -231,15 +231,32 @@ This flag, when combined with other flags, makes them produce extra output.
231231

232232
## `--extern`: specify where an external library is located
233233

234-
This flag allows you to pass the name and location of an external crate that
235-
will be linked into the crate you are building. This flag may be specified
236-
multiple times. This flag takes an argument with either of the following
237-
formats:
234+
This flag allows you to pass the name and location for an external crate of a
235+
direct dependency. Indirect dependencies (dependencies of dependencies) are
236+
located using the [`-L` flag](#option-l-search-path). The given crate name is
237+
added to the [extern prelude], which is the same as specifying `extern crate`
238+
within the root module. The given crate name does not need to match the name
239+
the library was built with.
240+
241+
This flag may be specified multiple times. This flag takes an argument with
242+
either of the following formats:
238243

239244
* `CRATENAME=PATH` — Indicates the given crate is found at the given path.
240245
* `CRATENAME` — Indicates the given crate may be found in the search path,
241246
such as within the sysroot or via the `-L` flag.
242247

248+
The same crate name may be specified multiple times for different crate types.
249+
For loading metadata, `rlib` takes precedence over `rmeta`, which takes
250+
precedence over `dylib`. If both an `rlib` and `dylib` are found, an internal
251+
algorithm is used to decide which to use for linking. The [`-C prefer-dynamic`
252+
flag][prefer-dynamic] may be used to influence which is used.
253+
254+
If the same crate name is specified with and without a path, the one with the
255+
path is used and the pathless flag has no effect.
256+
257+
[extern prelude]: ../reference/items/extern-crates.html#extern-prelude
258+
[prefer-dynamic]: codegen-options/index.md#prefer-dynamic
259+
243260
## `--sysroot`: Override the system root
244261

245262
The "sysroot" is where `rustc` looks for the crates that come with the Rust

0 commit comments

Comments
 (0)