-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Cannot link to --crate-type dylib
#34909
Comments
The workaround for us was to define a process where all git repos have zero tests, and all tests are moved into another git repo. It's critical for us that we can build a Rust DSO. |
@MarkSwanson note that the crate type "cdylib" is most appropriate for creating a Rust DSO. If you're trying to use a dylib linking to other Rust dylibs it'll be a nonstop world of pain right now unfortunately, but cdylib should be quite smooth. |
If this were a diamond dependency, where D depends on B and C which in turn both depend on A:
would you also expect this to work? Currently if you build B and C as dynamic, then they will each link their own static copy of A. When you try to link both into A, it will fail with The simplest thing is if A is dynamically linked to both B and C, so a single instance is shared between B and C, and there's no need to disambiguate them. (Edit: swapped A and D to match the answer below) |
@jsgf it depends on how all the linkages work out, we've got a test for this in tree for the various versions though. The gist is:
The only failure mode is when B/C are both dylibs, statically linking A, so D can't be guaranteed one copy of A. In other cases A is only included once as it's statically linked into only one dylib. The compiler isn't very smart about this today, though. It has a very simple heuristic where if it doesn't work on the first try it emits an error. |
Compiling it like this does work: > rustc foo.rs --crate-type dylib -C prefer-dynamic
> rustc bar.rs -L . But then you have to dynamically link to |
Is there any plan for the fix? Should I make every module |
I believe that there's no reason this executable couldn't be created, it should just use all dependencies through the dylib that was created in the previous step.
The text was updated successfully, but these errors were encountered: