Skip to content

#[link] not before extern is silently ignored #13695

Closed
@kornelski

Description

@kornelski
#[link(name="bad")]
fn main() {
}

compiles without warnings. I would expect warning that the link is unused or in the wrong place.

This causes a gotcha: if you insert any code between link and extern you suddenly get linker errors, because there's no -llibrary flag added.

#[link(name="library")]

struct SURPRISE();

extern {
    pub fn library() -> ();
}

fn main() {
    unsafe {
        library();
    }
}

I've got bitten by this when I've moved #[link] next to extern crate and #![crate_id] statements that I thought it belongs with.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions