-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Improve error message when attempting to use a crate that was created as a staticlib instead of an rlib. #14416
Comments
I can mentor this. |
What would working on this entail? |
Hey I'd like to work on this issue - it looks like we'll need to work on the linker. I'm reading up on it to work out what might need changing. |
The linker doesn't need to be modified. The error message today comes out of src/librustc/metadata/loader.rs:133. It just needs to be smarter about looking at the candidates it did find, and what was requested to link against, rather than just saying "not found". |
Cool - this could be done in one of two places in
I think it would be better suited in |
Hey @cmr, I've been trying to do some work on this - I'm having trouble finding where exactly the path gets searched to find possible crates. Any idea where it might be?
Also the speed of compilation is a bit of a bottleneck :p |
Can I fix this? I found a place where loader looks for candidates for crates. Relevant code looks like this:
So, we can add our warning message to the last else clause. We need to be careful though. I've discovered with RUST_LOG that rustc first looks for all files in its path (isn't it ineffective on directories with many files?). Then the loader does what showed above: tries to match filename to rlib or dypair. By comparing crate name with "lib{crate_name}.a" we can catch mentioned in the issue case. We probably should to check for .so files too? |
We need to be even more careful. I've used |
Now loader suggests to set crate type explicitly if it founds file with name similar to crate name, but different extension. This commit adds warning if loader found static library instead of rlib or dylib. It fixes issue rust-lang#14416.
Example output:
|
…crichton Add special error for this case and help message `please recompile this crate using --crate-type lib`, also list found candidates. See issue #14416 r? @alexcrichton
Fixed in #21978 |
If a crate is created as a staticlib, which is for linking against C programs, the error message that is gotten when trying to use that create from Rust is:
It would be better if the error message were:
Or something similarly useful.
Thanks.
The text was updated successfully, but these errors were encountered: