@@ -122,6 +122,9 @@ specifies the kind of library with the following possible values:
122122- ` static ` — Indicates a static library.
123123- ` framework ` — Indicates a macOS framework. This is only valid for macOS
124124 targets.
125+ - ` raw-dylib ` - Indicates a dynamic library where the compiler will generate
126+ an import library to link against (see [ ` dylib ` versus ` raw-dylib ` ] below
127+ for details). This is only valid for Windows targets.
125128
126129The ` name ` key must be included if ` kind ` is specified.
127130
@@ -198,6 +201,22 @@ The default for this modifier is `-whole-archive`.
198201More implementation details about this modifier can be found in
199202[ ` whole-archive ` documentation for rustc] .
200203
204+ #### ` dylib ` versus ` raw-dylib `
205+
206+ On Windows, linking against a dynamic library requires that an import library
207+ is provided to the linker: this is a special static library that declares all
208+ of the symbols exported by the dynamic library in such a way that the linker
209+ knows that they have to be dynamically loaded at runtime.
210+
211+ Specifying ` kind = "dylib" ` instructs the Rust compiler to link an import
212+ library based on the ` name ` key, the linker will then use its normal library
213+ resolution logic to find that import library. Alternatively, specifying
214+ ` kind = "raw-dylib: ` instructs the compiler to generate an import library
215+ during compilation and provide that to the linker instead.
216+
217+ Some non-Windows platforms have concepts similar to import libraries, but Rust
218+ currently only supports ` raw-dylib ` on Windows.
219+
201220### The ` link_name ` attribute
202221
203222The ` link_name ` attribute may be specified on declarations inside an ` extern `
@@ -211,6 +230,40 @@ extern {
211230}
212231```
213232
233+ Using this attribute with the ` link_ordinal ` attribute will result in a
234+ compiler error.
235+
236+ ### The ` link_ordinal ` attribute
237+
238+ This attribute is only used with the ` raw-dylib ` linking kind.
239+ It is ignored if used with any other kind.
240+
241+ On Windows, symbols exported from a dynamic library can either be found using
242+ their name or by a unique number call an "ordinal". The ` link_ordinal `
243+ attribute can be applied on declarations inside an ` extern ` block to indicate
244+ the ordinal to use when generating the import library to link against.
245+
246+ <div class =" warning " >
247+
248+ Warning: ` link_ordinal ` should only be used in cases where the ordinal of the
249+ symbol is known to be stable: if the ordinal of a symbol is not explicitly set
250+ when its containing binary is built then one will be automatically assigned to
251+ it, and that assigned ordinal may change between builds of the binary.
252+
253+ </div >
254+
255+ <!-- ignore: Only works on x86 Windows -->
256+ ``` rust,ignore
257+ #[link(name = "exporter", kind = "raw-dylib")]
258+ extern "stdcall" {
259+ #[link_ordinal(15)]
260+ fn imported_function_stdcall(i: i32);
261+ }
262+ ```
263+
264+ Using this attribute with the ` link_name ` attribute will result in a
265+ compiler error.
266+
214267### Attributes on function parameters
215268
216269Attributes on extern function parameters follow the same rules and
@@ -233,3 +286,4 @@ restrictions as [regular function parameters].
233286[ regular function parameters ] : functions.md#attributes-on-function-parameters
234287[ `bundle` documentation for rustc ] : ../../rustc/command-line-arguments.html#linking-modifiers-bundle
235288[ `whole-archive` documentation for rustc ] : ../../rustc/command-line-arguments.html#linking-modifiers-whole-archive
289+ [ `dylib` versus `raw-dylib` ] : #dylib-versus-raw-dylib
0 commit comments