Statically linked mingw binaries


I was trying to create a nix develop shell for building statically linked mingw binaries. The default mingw stdenv is incomplete because of: provides slightly incomplete linking environment: `cannot find -lmcfgthread` · Issue #156343 · NixOS/nixpkgs · GitHub

So I had to manually add mcfgthreads to buildInputs. The problem is only has shared libraries. I also tried It somehow triggered a build of mingw-w64-static-i686-w64-windows-gnu-10.0.0-headers, and that failed with this weird error:

       last 10 log lines:
       > checking for i686-w64-windows-gnu-strip... no
       > checking for strip... no
       > checking for a race-free mkdir -p... /nix/store/khndnv11g1rmzhzymm1s5dw7l2ld45bc-coreutils-9.4/bin/mkdir -p
       > checking for gawk... gawk
       > checking whether make sets $(MAKE)... yes
       > checking whether make supports nested variables... yes
       > checking whether to enable maintainer-specific portions of Makefiles... no
       > checking build system type... x86_64-unknown-linux-gnu
       > checking host system type... Invalid configuration 'i686-w64-windows-gnu': Kernel 'windows' not known to work with OS 'gnu'.
       > configure: error: /nix/store/9vafkkic27k7m4934fpawl6yip3a6k4h-bash-5.2-p21/bin/bash ./build-aux/config.sub i686-w64-windows-gnu failed

What’s the best way to do this?

1 Like

Note that you’re venturing off into unexplored territory. This platform is not supported by Nixpkgs in any way except that our generic mechanisms allow for it to be reasoned about.

Roadblocks like this aren’t just common, they’re expected.

What I am doing right now is: {
    dontDisableStatic = true;

Don’t know if this is the best way.

In patchelf we create a static windows binary like this:

hmm, interesting. so I can change the thread model so mcfgthread is not needed?

What’s mcfgthread for anyway? I think this is a new dependency, because I didn’t have this problem with older version of nixpkgs.

If I recall it provides threading primitives like pthread and locks.

The author replied in Update request: mcfgthreads git → 1.5-ga.2 · Issue #233099 · NixOS/nixpkgs · GitHub that the mcf thread model was merged into GCC 13. nixpkgs don’t apply the patch for GCC>=13.
It appears to me that pkgsCross.mingw32 is GCC 13 on nixpkgs master. Maybe you can try that (if you haven’t done so already).



Correction: While mcf support is natively supported in GCC>=13, it means that the mcfgthreads library is needed as extra dependency. This is done here and here. This also explains the magic from Mic92 for switching to the win32 threading mode.