Skip to content

Linker error when importing a some rlib's symbols through a dylib #17369

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
UberLambda opened this issue Sep 18, 2014 · 2 comments
Closed

Linker error when importing a some rlib's symbols through a dylib #17369

UberLambda opened this issue Sep 18, 2014 · 2 comments

Comments

@UberLambda
Copy link

Suppose having a project setup similiar to this one (replace _ in filenames with path separators).

The following conditions are met:

  • A static library, that I'll call A, has a public module in it
  • There's a dynamic library named B that has A as a Cargo dependency
  • B links to A with a extern crate A; statement, and exports some of A's modules with pub use A::module; in B's lib.rs
  • A binary/other library named C links to B and tries to use one of B's modules that are just a reexport of A modules

The linking of C with the default linker, fails with the following output:

error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/lib64/rustlib/x86_64-unknown-linux-gnu/lib' '-o' '/home/paolo/rust-bugs/C/target/C' '/home/paolo/rust-bugs/C/target/C.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive'
'-nodefaultlibs' '-fno-lto' '-Wl,--gc-sections' '-pie' '-Wl,--as-needed' '-L' '/home/paolo/rust-bugs/C/target/deps' '-lB-7ff4c82ee0366c0f' '-L' '/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lnative-4e7c5e5c' '-L' '/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib'
'-lstd-4e7c5e5c' '-L' '/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lsync-4e7c5e5c' '-L' '/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrustrt-4e7c5e5c' '-L' '/home/paolo/rust-bugs/C/target' '-L' '/home/paolo/rust-bugs/C/target/deps'
'-L' '/home/paolo/rust-bugs/C/.rust' '-L' '/home/paolo/rust-bugs/C' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-ldl' '-lpthread' '-lgcc_s' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: /home/paolo/rust-bugs/C/target/C.o: in function "C::main":
/home/paolo/rust-bugs/C/src/main.rs:6: undefined reference to "amod::Test::new::hbd984620e5bd9235oaa"
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Could not compile `C`.

If C links directly to A, whilst still linking to B, and tries to use A::amod instead of B::amod, the problem persists. Discarding B completely (e.g. without extern crate B in C's root) fixes it.

@alexcrichton
Copy link
Member

This is a dupe of #14344, but thanks for the test case!

@UberLambda
Copy link
Author

:)

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

2 participants