Skip to content

Fix Linking for MinGW Libraries on *-windows-gnu Targets #7927

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
wants to merge 6 commits into from

Conversation

camconn
Copy link
Contributor

@camconn camconn commented Jan 31, 2021

When building for *-windows-gnu targets, link against .dll.a import libraries instead of .dll files directly. LLD doesn't support linking against DLLs, but requires you to link against a .lib or .dll.a instead.

Fixes #7799.

- Searches for "libfoo.dll.a" for linking against when targeting
  mingw (Windows + GNU Abi)
- When targeting Mingw (windows + GNU Abi) use the ".dll.a" suffix for
  library files.
- NB: This is a hacky solution and the resulting linked program only
  works when launched from WITHIN a Mingw session. This probably has to
  do with how Mingw+Windows do library lookups.
@andrewrk
Copy link
Member

andrewrk commented Feb 1, 2021

Thanks for the PR. I have a different plan for this: #6565

On windows zig will only deal with .lib files, not .dll.a files.

@camconn
Copy link
Contributor Author

camconn commented Feb 1, 2021

Thanks Andrew,

The issue with using .lib for linking external system libraries is that Mingw uses the (.dll)?.a extensions which e.g. cause #7799 and breaks Zig's pkg-config integration on Mingw. Mingw doesn't ship with .lib files, but rather ships static .a or dynamic import .dll.a libraries. AFAICT these are the same as .lib with a different file extension. If I'm wrong on any of that, please correct me.

This PR is not concerned with what Zig uses internally, so go on ahead with #6565. It's more concerned with compatibility for external packages and what Zig passes to lld for linking.

I've added a commit that should fix the CI build. Would you like any other changes, or should this PR just be closed?

@andrewrk
Copy link
Member

andrewrk commented Feb 1, 2021

If you don't mind, please leave it open, and when I implement #6565 I will have all the context loaded in my mind to know how the ideas in this PR should be merged (or not). Sound OK?

@camconn
Copy link
Contributor Author

camconn commented Feb 2, 2021

Yeah that's fine. It's your code, so ultimately your say.

In the meantime I've pushed added a patch that should fix builds for windows targets on non-windows OSs.

@KioriSun
Copy link

KioriSun commented Feb 7, 2021

Hi all I tried compiling SDL2 on win with zig cc, and the current holdup is exactly that sdl ships with sdlLibs.a instead of .libs on the mingw devel.
I believe zig should just support the default for mingw.

@andrewrk
Copy link
Member

andrewrk commented Jun 8, 2021

Please see #7799 (comment) for how I am solving this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows: Linking step fails when trying to use MinGW SDL2 library (@cimport + gnu target)
3 participants