Skip to content

#[link_name] is ignored on extern blocks #47725

Closed
@cuviper

Description

@cuviper
fn main() {
    println!("{}", unsafe { foo() });
}

#[link_name = "foobar"]
extern "C" {
    fn foo() -> u32;
}

This fails to link with undefined reference to `foo', but it didn't even try to find any foobar library.

With #[link(name = "foobar")], the error is the expected ld: cannot find -lfoobar.

There are a few places in libstd using #[link_name = "m"] extern {...}, so I wonder if those actually have any effect either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-attributesArea: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions