-
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
Linker error "invalid library format; library ignored" only for debug builds on Windows #119092
Comments
In my ops folder, I used macro to implement operations for my struct with a bunch of different type, from bool to f64. If I remove all the operations and left only around 5 operations like Add, Sub, Div, Shr, etc, it can pass the compilation. However, if I add one more operations, link error will occur. |
What did you compile to produce this error? What version of Rust did you use? |
name = "Utensor" [wordspace] [dependencies] [[bin]] It is my workspace cargo.toml, I can see that most of the linking error are about iterator, but I am not sure why release mode can compile instead of debug. |
Can you point us to the source code you're compiling? If one of us can compile it there's a much better chance of figuring out what's going on here. |
https://github.com/Jianqoq/utensor-rs, this is the source code |
I can reproduce the error on Windows. Trying Linux... |
Thank you! Hopfully we can get it fix :) |
Hm, seems to manage to build on Linux which is unfortunate because I have almost no skill with Windows tooling. The build uses a pretty incredible amount of memory, so my first guess was that the object file is getting truncated or otherwise mangled because it's run over some limit in the linker or LLVM or in rustc. So I think it's possible this is a limitation of the Windows linker, or the code that breaks rustc/LLVM is being I did get this error when I switched from nightly to stable which suggests something is wrong:
|
It is also what I am thinking at, the memory problem. This build generate I think like at least 1000 of operations template, for example: bool + bool = bool, f32 + f64 = f64, stuff like that, generally, each operation would need to generate around 150 functions. But since there are not many, only add, sub, mul, div, rem, shl, shr, etc, shouldn't be that many. But anyway, since everything has to be implement in the same crate, so the amount of the work might huge. Do you think it is solvable? |
I think this is a
will build just fine. Any other way of setting your linker to |
Library files are a type of archive containing many object files. The first file in the archive is a directory of public symbols that's just called So the issue is that rustc is producing libraries in a format that MSVC does not understand and then passing them to the MSVC linker. Note that I'm pretty sure this is a compiler bug. |
Sorry, I have not tested 64-bit archive lookup tables with link.exe. The
Can you say how you determined that is the issue? If link.exe does not support 64-bit archive lookup tables, then I don't think there is anything rustc can do here? |
Well it can, for example, use two archives instead of one, no? Unless there's really no way to arrange things to fit then I support it would have to error.
By looking at the rlib that failed in a hex editor. See also Archive (Library) File Format. |
Cargo and basically every other build tool expect only a single file to be emitted, |
That's only true for rlibs. What matters here is only what's being sent to the linker, not the format of rlibs in general (which iirc are completely undocumented). Yes it's convenient if rlibs are directly compatible with the linker but if that's not possible a conversion step can happen completely invisibly when it's time to link. |
I guess. Wouldn't work for staticlibs though. |
My question was more of how you determined that not having a |
As you can see from Archive (Library) File Format (linked earlier), in msvc a lib file must start with
Opening up in the "invalid" lib file in a hex editor I see
The first member is not called Might there be other problems with the |
Oh, I see! Thanks! Yea, searching around it seems that 64-bit archives simply aren't supported. 😦 |
My program can get compile when I use --release, but if I don't use it, it will failed.
Platform: Windows 11
The text was updated successfully, but these errors were encountered: