Skip to content

Linker library order is important #11124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vadimcn opened this issue Dec 23, 2013 · 3 comments
Closed

Linker library order is important #11124

vadimcn opened this issue Dec 23, 2013 · 3 comments

Comments

@vadimcn
Copy link
Contributor

vadimcn commented Dec 23, 2013

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.

@alexcrichton
Copy link
Member

Another possible solution could be link(name = "foo", priority = "100") where the default priority is N and they're sorted lowest to highest, but it does seem odd that we're de-duping the libraries.

@sanxiyn
Copy link
Member

sanxiyn commented Mar 13, 2014

Did #12688 fix this?

@alexcrichton
Copy link
Member

It did indeed, a test was checked in as well.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 31, 2023
…ogiq

Rewrite [`tuple_array_conversions`]

Fixes rust-lang#11100
Fixes rust-lang#11144
Fixes rust-lang#11124

rust-lang#11082 still needs discussion and rust-lang#11085 likely can't be fixed.

changelog: [`tuple_array_conversions`]: Move to `pedantic`
changelog: [`tuple_array_conversions`]: Don't lint if mutability of references changes
changelog: [`tuple_array_conversions`]: Don't lint if bindings don't come from the exact same pattern
changelog: [`tuple_array_conversions`]: Don't lint if bindings are used for more than just the conversion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants