Skip to content

Loading an "extern mod" multiple times in separate files will throw error "Library 'X' already added" #5951

Closed
@dymk

Description

@dymk

Lets say you've got an extern module called 'X':

#[link_name = "MY_LIBRARY_LINK_NAME"]
#[link_args="-L/path/to/your/library/x"]
pub extern mod X {
    fn foo();
}

And files A, B, and C (lets say they define tests, or something), in a structure something like this:

/ -> 
    test ->
        a.rs
        b.rs
        c.rs
    lib ->
        x.rs

If one was to define B and C like so to load module X:

b.rs:

#[path = '../lib/x.rs']
mod x;

//and some test functions

c.rs:

#[path = '../lib/x.rs']
mod x;

//and some test functions

And then include both in 'a.rs'
a.rs:

mod a;
mod b;

The compiler would throw an error such as:
x.rs:0:0: 0:1 error: library 'MY_LIBRARY_LINK_NAME' already added: can't specify link_args.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binaries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions