Skip to content

Incorrect information about link attribute on extern blocks #1986

@wmmc88

Description

@wmmc88

[items.extern.attributes.link.intro] states:

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")]
unsafe extern "C" {}

/// Extern block with no `link`
unsafe extern "C" {
    /// This is a function in `libfoo`
    fn bar();
}

bar will be resolved with its implementation in the foo library, despite the link attribute being on a different extern block

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions