-
Notifications
You must be signed in to change notification settings - Fork 13k
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
MinGW: undefined reference to _imp___wassert #60912
Comments
What is your gcc and g++ version you used? Both in success and failure cases. |
If you're using an external MinGW toolchain to build C/C++ code you should also be using that MinGW toolchain to link everything, and not the MinGW that is bundled with Rust. |
@lzutao Both
@retep007 If I understand the situation correctly, there is no internal-to-Rust MinGW toolchain that can build C/C++ code, because the bundled I've seen this advice mentioned elsewhere (not involving Rust), and it sounds reasonable, but I would appreciate it if you could give me some background reasoning behind it or point me to some sources. Is it because of differences in ABI, symbol names, or something else? Thanks! That said, I guess you might expect the following to make a difference in this issue:
But it doesn't. The error is almost exactly the same as above. The only difference is |
Yes. Things change between MinGW versions and C/C++ code compiled against headers for a specific MinGW version are only guaranteed to link against libraries from that same MinGW version. Just changing the linker alone isn't enough because rustc still adds the paths to its bundled MinGW libraries in the linker invocation. You'd have to disable the bundled MinGW entirely. |
Right. I forgot to set the
How do I do that? |
I cannot reproduce it with There is similar issue #47048, you can try copying important libraries into rust toolchain directory:
Note: you may need to copy more libraries depending on the errors. |
@mati865 Does the symbol
Indeed! Copying |
I won't have access to Windows until evening (Europe time) and I have already overridden Rust shipped libs. I haven't made backup because they were broken in other ways. |
windows-gnu: prefer system crt libraries if they are available This is my proposal (based on `Amanieu`'s idea) on how to fix #47048 and related issues. The origin of the issue is the fact Rust ships mingw-w64 libraries but no headers and prefers own libraries over the system ones. This leads to situation when headers aren't compatible with libraries (mingw-w64 doesn't provide any forward compatibility and AFAIK backwards compatibility is guaranteed only within major release series). It's easier to understand how this PR works when looking at the linker invocation before and with this PR: https://www.diffchecker.com/GEuYFmzo It adds system libraries path before Rust libraries so the linker will prefer them. It has potential issue when system has files with the same names as Rust but that could be avoided by moving Rust shipped mingw-w64 libraries from `lib/rustlib/x86_64-pc-windows-gnu/lib` to say `lib/rustlib/x86_64-pc-windows-gnu/lib/mingw`. Then adding linker paths in this order: Rust libraries, system libraries, Rust shipped mingw-w64 libraries. I don't know if it's worth to cache system libraries path. You can look for `cache: ` string during build Rust: https://pastebin.com/kGEQZGWP I think there are enough calls to justify caching. Fixes #47048 Fixes #49078 Fixes #53454 Fixes #60912
There is a very particular set of circumstances that leads to the following error when compiling some C++ files and linking them into a Rust executable targeted at
stable-i686-pc-windows-gnu
:Summary: I believe the Rust MinGW toolchain needs to be rebuilt or updated to include
_imp___wassert
(which I believe is the dynamically linked_wassert
).I used the repository https://github.com/spl/rust-assert-unicode-test on a Windows VM with MSYS2 and MingW32 installed. Unfortunately, I could not reproduce the issue on Travis-CI or AppVeyor, but it happens reliably on my VM. (I don't have MSVC installed, but I don't know if that's the reason.)
These are the key files:
src/val.h
:src/val.cpp
:build.rs
:For context, here is the snippet that defines
assert()
inassert.h
from mingw-w64:With nothing in the environment, the build succeeds:
It's useful to look at the symbols in the library:
With
-DUNICODE
, the build fails:Looking at the symbols in the library confirms that
_imp___wassert
is there (and that__imp___assert
is not, as would be expected):One way to work around this issue is to link directly to the MinGW
msvcrt
library:Looking at what was linked with Process Monitor, I found that the bundled
msvcrt
library was being used. And, indeed, that library is missing__imp___wassert
:Looking at the symbols in MinGW's
msvcrt
, I can now see why linking to it works:There are no definitions of the
__imp___wassert
symbol inC:/.../.rustup/toolchains/stable-i686-pc-windows-gnu/lib/rustlib/i686-pc-windows-gnu/lib/*.a
.The text was updated successfully, but these errors were encountered: