-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Using dylib as dependency without -Cprefer-dynamic doesn't work #90539
Comments
This issue has been one year and I can confirm it with a recent compiler (
What's the current state of the issue (about the expected behavior or any plan to fix it)? Also, I will be grateful if anyone could point me to the source code for the 'fundamental' reason of not being able to have the same dependency show up more than once. I've been stuck by various linkage issues about dynamic libraries in rust for weeks. I've seen people discuss this problem around (#34909 #3573) but could never figure out the underlying reason. @bjorn3 @alexcrichton |
The same crate not being allowed to show up in more than one linked artifact (dylib or executable) is deliberate. Duplication will lead to either symbol conflicts or symbols being duplicated. Neither of which is acceptable as it will break the guarantee that statics are never duplicated and with it break any crate using global state, including the standard library itself. This issue however is about rustc deciding to dynamically link libstd despite the fact that it is already included in the dylib. This is something that can and should be fixed. |
Now I get it. This sounds quite reasonable and convincing. I also saw the following description about library duplication in this RFC just now.
Thanks so much for your explanation @bjorn3! |
What if libstd is a dylib? |
The problem is exactly that libstd is available as both an rlib and dylib. Without |
This is a rustc bug or a cargo bug? I.e., should this intelligence of deciding whether to use What if the |
Cargo already passes This issue is about a rustc bug. |
I tried this:
I expected to see this happen: It compiles and
b
dynamically links toliba.so
which itself statically links to libstd.Instead, this happened:
Making it work currently requires passing
-Cprefer-dynamic
when compilingliba.so
.Meta
rustc --version --verbose
:This seems to have been the reason for a new test in #89836 failing.
The text was updated successfully, but these errors were encountered: