-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Linking to a static library does not always include exported symbols #99721
Comments
That's the nature of static library; there's not much we can do about it unless we squeeze everything into one single object file or reference all object files from every single one of them. |
That makes sense. I just found that you can force link the symbol with I'll resort to using the |
You need |
That won't work either. Object file inside static libs will not participate in linker if it does not provide any undefined symbol. SHF_GNU_RETAIN are not special in this regard. |
Yeah, that does not work unfortunately. |
There's a similar issue that can be fixed. You link a staticlib (written in C, or Rust, or whatever) to a binary, and you want to preserve some symbol from it. // bin.rs
#[link(name = "my_staticlib")]
extern "C" {
#[used(linker)]
fn some_symbol_from_my_staticlib_that_needs_to_be_kept();
#[used(linker)]
static SAME_BUT_STATIC: u8;
} Unfortunately, If it worked it would refer to the symbol in question from |
Interesting! Since in our use case we want to distribute the static library, this won't work. It's great that you can use |
Similarly to #47384, statics in a static library that are marked as
used
are not included in the resulting binary if a non-inlined function is used in the same module.Example
This code can be found at
mkroening/rust-issue-99721
.staticlib.rs
:bin.rs
:Build using:
Display static library notes:
Display binary notes:
If
note::dummy
is madeinline(never)
, the symbol is included in the resulting binary:The text was updated successfully, but these errors were encountered: