Skip to content

Linking hello world program fails under Windows when other MingW is in PATH #17726

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

Closed
catch22 opened this issue Oct 2, 2014 · 2 comments · Fixed by #18797
Closed

Linking hello world program fails under Windows when other MingW is in PATH #17726

catch22 opened this issue Oct 2, 2014 · 2 comments · Fixed by #18797
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler A-linkage Area: linking into static, shared libraries and binaries O-windows Operating system: Windows

Comments

@catch22
Copy link

catch22 commented Oct 2, 2014

Building the hello world program fails with the following message:

error: linking with `gcc` failed: exit code: 1
note: gcc '-m64' [snip]
note: C:\Tools\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib(native-4e7c5e5c.o):(.text+0x89): undefined reference to `_Unwind_Resume'
C:\Tools\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib(native-4e7c5e5c.o):(.text+0x5bb): undefined reference to `_Unwind_Resume'
C:\Tools\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib(native-4e7c5e5c.o):(.text+0x12c8): undefined reference to `_Unwind_Resume'
C:\Tools\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib(native-4e7c5e5c.o):(.text+0x1396): undefined reference to `_Unwind_Resume'
C:\Tools\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib(native-4e7c5e5c.o):(.text+0x1463): undefined reference to `_Unwind_Resume'
C:\Tools\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib(native-4e7c5e5c.o):(.text+0x1781): more undefined references to `_Unwind_Resume' follow
c:/tools/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Tools\Rust\bin\rustlib\x86_64-w64-mingw32\lib\libnative-4e7c5e5c.rlib(native-4e7c5e5c.o): bad reloc address 0x0 in section `.data'
collect2.exe: error: ld returned 1 exit status

It appears that rustc picks up another MingW's version of ld rather than the one it ships with. The same error also appears if the rust binary directory is the first item in my PATH. The only way around it is to either remove my MingW's bin directory from the PATH or by prefixing rustlib/...mingw/gcc/bin to the PATH. Both solutions seem to be quite hackish -- I just wanted to check if this is the desired behavior.

@kmcallister kmcallister added O-windows Operating system: Windows A-linkage Area: linking into static, shared libraries and binaries A-driver Area: rustc_driver that ties everything together into the `rustc` compiler labels Oct 4, 2014
@vadimcn
Copy link
Contributor

vadimcn commented Oct 4, 2014

... if this is the desired behavior.

Yes, please see #17442.

bors added a commit that referenced this issue Nov 11, 2014
Based on Windows bundle feedback we got to date, 
- We *do* want to prefer the bundled linker: The external one might be for the wrong architecture (e.g. 32 bit vs 64 bit).  On the other hand, binutils don't add many new features these days, so using an older bundled linker is not likely to be a problem.
- We *do* want to prefer bundled libraries: The external ones might not have the symbols we expect (e.g. what's needed for DWARF exceptions vs SjLj).  Since `-L rustlib/<triple>/lib` appears first on the linker command line, it's a good place to keep our platform libs that we want to be found first.

Closes #18325, closes #17726.
@jeffnyman
Copy link

I understand this is closed and I also looked at the related issues but it's very unclear what the actual resolution was here. Using the following:

stable-x86_64-pc-windows-gnu (default)
rustc 1.57.0 (f1edd0429 2021-11-29)

The issue above still happens on a fresh install of Rust via rustup and using the above toolchain. Specifically, I see the error:

collect2.exe: error: ld returned 1 exit status

And it's clear that the Rust toolchain is using an existing mingw32 setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler A-linkage Area: linking into static, shared libraries and binaries O-windows Operating system: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants