You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect information about link attribute on extern blocks #1986
The link attribute specifies the name of a native library that the compiler should link with for the items within an extern block.
The incorrect part of this statement is for the items within an extern block. The link attribute seems to behave exactly like rustc-link-lib which just adds a linker argument to link against another library. The current wording in the reference implies that it will only try to link the items within that specific extern block to the library, but any external symbol could be resolved by that library.
Example
/// Empty extern block#[link(name = "foo")]unsafeextern"C"{}/// Extern block with no `link`unsafeextern"C"{/// This is a function in `libfoo`fnbar();}
bar will be resolved with its implementation in the foo library, despite the link attribute being on a different extern block
Also, conversely, I believe that (unless you have an explicit link_ordinal attribute on windows), symbols in a #[link] extern block can be resolved by any library, and not just the linked-in one.
Activity
chorman0773 commentedon Aug 30, 2025
Also, conversely, I believe that (unless you have an explicit
link_ordinalattribute on windows), symbols in a#[link]extern block can be resolved by any library, and not just the linked-in one.