Skip to content

Linker library order is important #11124

Closed
@vadimcn

Description

@vadimcn

Let's say I have 3 modules main.rs, a.rs and b.rs, and two external libraries libfoo.a and libbar.a, and that libbar depends on symbols defined in libfoo.

main.rs

mod a;
mod b;
fn main() {}

a.rs

#[link(name = "foo")]
extern {}

b.rs

#[link(name = "bar")]
#[link(name = "foo")]
extern {}

Because rustc de-dupes the list of external libraries, it will pass to linker only -lfoo -lbar. However gnu linker does not look for unresolved symbols in libraries it had already processed, so it will fail to resolve libbar's references to libfoo. The correct command line would have been -lfoo -lbar -lfoo.

Rustc should not de-duplicate the list of libraries. Furthermore, I think it should guarantee that libs will appear in the same order on the linker command line as they did in the source file.

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