-
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
Windows: Static libraries should end with .a not .lib when using MinGW/GCC #43749
Comments
Also cc @vadimcn, do you think we could change this back for MinGW? |
Doesn't look like a regression to me. It's been this way for quite some time (2 years?). The immediate cause seems to be this line in example's Makefile, which assumes that the output library will use Unix naming convention. I'm not sure what would be the proper way of writing that Makefile: |
@vadimcn: I'd think changing to .a for gcc would be fitting for two reasons:
|
My PR made it follow whatever the target options for that target were. For some obscure reason the windows gnu targets were configured to use I have absolutely no issue with changing the windows gnu target specification to use |
@stuij: .a and .lib files are exactly equivalent, it's just a different naming convention. AFAIR, the idea of the original PR was to follow the platform convention. MinGW itself sort of sits on both chairs, because given -lname it will find both libname.a and name.lib libraries. We could change it, but that still leaves -msvc toolchain, which arguably should follow MSVC convention. |
@vadimcn: and now I'm confused. According to the internets, .lib and .a files, although similar, are not the same format. And there are tools to convert the one into the other. Could you clarify for me how this relates to the format that Rust outputs? |
@stuij: Can you please provide a link? As far as I know, they are the same. |
@vadimcn: you're right about the format. The binary format for both seems to be COFF object files wrapped in ar archives. Although I couldn't find any definite proof for MinGW. I think why people have been writing/finding that they're incompatible is because they've been created by different toolchains. The closest that I've managed to get to a stance/an advice is this mingw thread, which basically says: don't mix artifacts from different toolchains. Also plain C ABI files might work, but it might also not. 64-bit definitely won't work apparently. I don't understand why: I still feel that moving to .a naming makes sense. why not follow MinGW conventions for MinGW and follow the MSVC conventions for MSVC? It will confuse people less. You shouldn't actually mix the two. You don't have to have to put hackish things in makefiles. What are the upsides of sticking with the current situation? |
@stuij, what people are talking about is C++ ABI compatibility, and it's true - you can't link g++ object files to VC++ ones. Plain C ABI, on the other hand, is 100% compatible, as far as I know.
"When on Windows, do as Microsoft does". We wanted to have platform-native feel for Windows Rust port, and that means using name.lib convention. Some Windows-native tools might not support libname.a format at all.
That's debatable. I would argue that it's less confusing to have our two Windows toolchains behave similarly.
Not disturbing workflows and tools that people had built around the current way of doing things? |
The C ABI is compatible between MinGW and MSVC when it comes to the I have never seen the Besides, gnu makefiles aren't going to be written for msvc, so the choice isn't between having a special case for Windows or a special case for MSVC, it is a choice between having a special case at all and no special case. That said, the fact that this change has been sitting around for nearly two years makes me wonder about what code out there would be broken by us reverting back to |
@vadim ah yes sorry, but to clarify this was a 1.7.0 -> 1.8.0 regression (wow that's old!). In 1.7.0 we'd create It sounds like though we agree that In that sense I think I'd personally advocate for not changing the current state of affairs. It'd be another unfortunate breaking change this time to switch the output name (which may go noticed this time!). @stuij for you, though, does @vadimcn's original suggestion work for implemented a "cross platform makefile"? |
@alexcrichton I resolved it in autoconf during makefile generation, although @vadimcn's idea is a bit more convenient. |
Ok good to know! If that's the case then I'm going to go ahead and close this as while a bug and indeed a historical regression, at this point we're probably unlikely to fix it due to the more regressions it'd cause to fix. |
Cool. Thanks all, for exploring this. |
@alexcrichton This bug is causing real issues when creating static libraries for To workaround it build systems have to create Downstream issues: |
I'd like to echo the desire for cargo to produce |
@mati865 this issue is nearly 2 years old and I'm only very tangentially related to this. I think it's probably best if a new issue were opened up instead of reviving a long-closed issue. |
@alexcrichton Out of curiosity, what is the advantage of opening a new issue that would lack all of the above background information? I found it to be very valuable. |
This issue is years old and has lots of outdated information. A new issue serves to provide refreshed view of the world and ensure it's accurate and up to date. You can even link to this issue and take excerpts from it if it's still true today. |
I hit this issue today. I am using CMake and got around it by changing the expected filename of the target to be linked, which is a static library. |
Ran into this myself, and yea quite confusing. |
We're using MinGW compiler to cross-compile to Windows which will produce static libraries ending with .a extention Here's an interesting read about it: rust-lang/rust#43749 (comment)
It looks like there might be a regression on Windows, where Rust static libraries built with/for MinGW have the MSVC naming, instead of GCC naming. So the shared library has a .lib suffix, and isn't prepended with 'lib'. This seems to be the reverse of issue #29508.
My pared down test case was the rust-ffi-examples code, which because of this is currently broken for an MSYS2 setup (I hope I have done something wrong):
The text was updated successfully, but these errors were encountered: