Trying to cross-compile to `i686-pc-windows-gnu`

I’m trying to cross compile some Rust application to Windows without using the nix build system so I can take advantage of the incremental compilation via devShells.

This application requires that I compiles to i686-pc-windows-gnu. Looking at their GitHub workflow, the only dependency they’ve installed is gcc-mingw-w64-i686 through apt. My problem is that, what is the equivalent of that package in Nix?

Without adding anything at all, the error message is

error: error calling dlltool 'i686-w64-mingw32-dlltool': No such file or directory (os error 2)

I’ve tried a few things but the first package that make some progress is

pkgs.pkgsCross.mingw-msvcrt-i686.buildPackages.gcc

Then I hit with the error

error: linking with `i686-w64-mingw32-gcc` failed: exit status: 1
  |
  = note:  "i686-w64-mingw32-gcc" "-Wl,/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustc1RtNxm/list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-Wl,--large-address-aware" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "<1 object files omitted>" "-Wl,-Bstatic" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustc1RtNxm/{libgetrandom-44ceb6cc5c517428,liblibloading-f5dc22747605714e,libstd-246a1e027a2e9cea}.rlib" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libcompiler_builtins-90c2a00ecbe05553.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lkernel32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-ldbghelp" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-o" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/ewext.dll" "-Wl,--gc-sections" "-shared" "-Wl,--out-implib=/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libewext.dll.a" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: cannot find -l:libpthread.a: No such file or directory
          collect2: error: ld returned 1 exit status

I used nix-locate to find libpthread.a. What seems to work is

pkgs.pkgsCross.mingw-msvcrt-i686.buildPackages.musl

And I’m hit with another error

error: linking with `i686-w64-mingw32-gcc` failed: exit status: 1
  |
  = note:  "i686-w64-mingw32-gcc" "-Wl,/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustcp9SF3f/list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-Wl,--large-address-aware" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "<1 object files omitted>" "-Wl,-Bstatic" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustcp9SF3f/{libgetrandom-44ceb6cc5c517428,liblibloading-f5dc22747605714e,libstd-246a1e027a2e9cea}.rlib" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libcompiler_builtins-90c2a00ecbe05553.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lkernel32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-ldbghelp" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-o" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/ewext.dll" "-Wl,--gc-sections" "-shared" "-Wl,--out-implib=/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libewext.dll.a" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x160a): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x16a9): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x176e): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x17ef): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x187f): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x191b): more undefined references to `_MCF_mutex_lock_slow' follow
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1a05): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1a74): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1a8c): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1c67): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1c8f): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1ca6): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1621): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x16bf): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1758): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1805): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1895): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1932): more undefined references to `_MCF_mutex_unlock_slow' follow
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0xb): undefined reference to `_MCF_tls_key_new'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x4c): undefined reference to `_MCF_once_wait_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x6c): undefined reference to `__MCF_gthr_call_once_seh_take_over'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0xc7): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0xde): undefined reference to `__MCF_tls_table_get'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x1f0): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x211): undefined reference to `__MCF_tls_table_xset'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x30a): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x331): undefined reference to `__MCF_tls_table_xset'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x3e1): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x3fd): undefined reference to `__MCF_tls_table_get'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x41f): undefined reference to `__MCF_tls_table_xset'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x469): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x48c): undefined reference to `__MCF_tls_table_xset'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x5b2): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x5c9): undefined reference to `__MCF_tls_table_get'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x69c): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x6b3): undefined reference to `__MCF_tls_table_get'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x7e2): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x7f9): undefined reference to `__MCF_tls_table_get'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

After a few searches, this is likely related to this thread.

I tried to add another package

pkgs.pkgsCross.mingw-msvcrt-i686.buildPackages.windows.mcfgthreads

Then I got hit with the

       error: Refusing to evaluate package 'mcfgthread-2.3.1' in /nix/store/8xjxn3pz0mkfcr6jk6cfnhrjxw8v0f3l-source/pkgs/os-specific/windows/mcfgthreads/default.nix:41 because it is not available on the requested hostPlatform:
         hostPlatform.system = "x86_64-linux"
         package.meta.platforms = [
           "aarch64-windows"
           "x86_64-windows"
           "i686-windows"
         ]
         package.meta.badPlatforms = [ ]

Which is a bit confusing (hostPlatform.system = "x86_64-linux"..?), because I’m trying to cross-compile here, similarly to the mentioned thread above. But that’s still unanswered. Why? Or was it that mcfgthreads is not supported on `i686-pc-windows-gnu`? Then, maybe I should change to something else? How?

I think it is pkgsCross.mingw32.buildPackages.gcc, the targetPrefix is i686-w64-mingw32-and the libc is mingw-w64-i686-w64-mingw32.

error: linking with `i686-w64-mingw32-gcc` failed: exit status: 1
  |
  = note:  "i686-w64-mingw32-gcc" "-Wl,/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustcxXTGKB/list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-Wl,--large-address-aware" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "<1 object files omitted>" "-Wl,-Bstatic" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustcxXTGKB/{libgetrandom-44ceb6cc5c517428,liblibloading-f5dc22747605714e,libstd-246a1e027a2e9cea}.rlib" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libcompiler_builtins-90c2a00ecbe05553.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lkernel32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-ldbghelp" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-o" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/ewext.dll" "-Wl,--gc-sections" "-shared" "-Wl,--out-implib=/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libewext.dll.a" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: cannot find -l:libpthread.a: No such file or directory
          collect2: error: ld returned 1 exit status

Try with only pkgsCross.mingw32.buildPackages.gcc and recompiled from scratch. Is there anything else I should do beside adding the package? (I’ve also tried this with the other packages I’ve added previously which ended up with basically the same chain of linker errors)

I forgot to mention but anway, the error without any dependency at all is

error: error calling dlltool 'i686-w64-mingw32-dlltool': No such file or directory (os error 2)

This only gives you the toolchain (linker, compiler, etc.) to run on the hostPlatform (e.g. x86_64-linux) generating code for the targetPlatform(in this case i686-w64-mingw32).

You still need to provide libraries for the linker to link against.

The error listed is that it cannot find the static library of libpthread. It is provided by pkgsCross.mingw32.windows.pthreads.

pkgsCross.mingw32.windows.pthreadsis one of the dependency I’ve tried already and they refused to evaluated with the same error message as mcfgthreadsas I mentioned previously.

If I went ahead and evaluated anyway, the entire gcc is recompiled and failed.

Edit: Interestingly, If I try to build the package within nix repl, they built just fine. I wonder if there is something wrong with my devshell?

Before you done this:

The reason you got the hostPlatform error is that you used buildPackages. If you just use pkgsCross.mingw32.windows.pthreadsyou will not get a hostPlatform error.

buildPackagesis for packages that need to run on the buildPlatform. The library does not need to run on the build platform; it only needs to be available for linking for the host platform.


In short, when cross compiling on x86_64-linux for i686-windows:

  • pkgsCross.mingw32.windows.pthreads is the library built for i686-windows.
  • pkgsCross.buildPackages.mingw32.windows.pthreads is the library built for x86_64-linux.

As the library is Windows only, the second one fails.

I’ve tried pkgsCross.mingw32.windows.pthreads exactly. Same error.

How are you defining pkgsCross? And what error are we talking about, hostPlatform error or file not found error?

Simplifying the original flake a bit, which should looks like

let pkgs = import nixpkgs {
  localSystem = system;
  overlays = [ /* rust overlay*/ ];
});
in
{
  devShells."x86_64-linux".default = 
    pkgs.mkShell {
      packages = [
        (pkgs.rust-bin.selectLatestNightlyWith (/* ... */))
        pkgs.pkgsCross.mingw32.buildPackages.gcc
        pkgs.pkgsCross.mingw32.windows.pthreads
      ];
    };
}

The error is

       error: Refusing to evaluate package 'mingw_w64-pthreads-13.0.0' in /nix/store/8xjxn3pz0mkfcr6jk6cfnhrjxw8v0f3l-source/pkgs/os-specific/windows/mingw-w64/headers.nix:35 because it is not available on the requested hostPlatform:
         hostPlatform.system = "x86_64-linux"
         package.meta.platforms = [
           "aarch64-windows"
           "x86_64-windows"
           "i686-windows"
         ]
         package.meta.badPlatforms = [ ]

That is because you have put it in packages, which is for executables to add to the shell environment (i.e. it needs to run on the hostPlatform). It should be in buildInputs.

I see. I was under the impression that packages and builtInputs behaves the same.

The pthreads package builds successfully, though, the linker error continues.

error: linking with `i686-w64-mingw32-gcc` failed: exit status: 1
  |
  = note:  "i686-w64-mingw32-gcc" "-Wl,/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustc96wCjP/list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-Wl,--large-address-aware" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "<1 object files omitted>" "-Wl,-Bstatic" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustc96wCjP/{libgetrandom-4ed502623c412aa1,liblibloading-6e5722be184be636,libstd-1b03d3431077269e}.rlib" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libcompiler_builtins-446745936342c66a.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lkernel32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-ldbghelp" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-o" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/ewext.dll" "-Wl,--gc-sections" "-shared" "-Wl,--out-implib=/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libewext.dll.a" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "-Wl,-rpath,/nix/store/a1hjv7q257wlf0ixf8i8jbnfg51xqwsh-mingw_w64-pthreads-i686-w64-mingw32-13.0.0/lib" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: cannot find -l:libpthread.a: No such file or directory
          collect2: error: ld returned 1 exit status

I’ve also tried setting LD_LIBRARY_PATH and RUSTFLAGS

  env =
    let
      libs = lib.makeLibraryPath [ pkgs.pkgsCross.mingw32.windows.pthreads ];
    in
    {
      LD_LIBRARY_PATH = libs;
      RUSTFLAGS = "-C link-arg=-Wl,-rpath,${libs}";
    }; 

Try adding this to your RUSTFLAGS, with RUSTFLAGS being a list.

++ (builtins.map (a: ‘‘-L ${a}/lib’’) [pkgs.pkgsCross.mingw32.windows.pthreads])

I’m not entirely sure what do you mean by RUSTFLAGS a list.

       error: The `env` attribute set can only contain derivation, string, boolean or integer attributes. The `RUSTFLAGS` attribute is of type list.

So, I did

  env = {
    RUSTFLAGS = lib.concatStringsSep " " (map (a: "-L ${a}/lib") libs);
  };

with libs being [ pkgs.pkgsCross.mingw32.windows.pthreads ]

This does works! So we’ve got… different linker errors

error: linking with `i686-w64-mingw32-gcc` failed: exit status: 1
  |
  = note:  "i686-w64-mingw32-gcc" "-Wl,/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustcy88bhL/list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-Wl,--large-address-aware" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "<1 object files omitted>" "-Wl,-Bstatic" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustcy88bhL/{libgetrandom-dd10243c59e15ffd,liblibloading-00a8a0c56fac1091,libstd-c3ceaa62f350c718}.rlib" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libcompiler_builtins-87df5a0146224add.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lkernel32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-ldbghelp" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-L" "/nix/store/a1hjv7q257wlf0ixf8i8jbnfg51xqwsh-mingw_w64-pthreads-i686-w64-mingw32-13.0.0/lib" "-o" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/ewext.dll" "-Wl,--gc-sections" "-shared" "-Wl,--out-implib=/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libewext.dll.a" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x160a): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x16a9): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x176e): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x17ef): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x187f): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x191b): more undefined references to `_MCF_mutex_lock_slow' follow
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1a05): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1a74): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1a8c): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1c67): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1c8f): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1ca6): undefined reference to `_MCF_mutex_lock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1621): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x16bf): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1758): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1805): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1895): undefined reference to `_MCF_mutex_unlock_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-dw2-fde.o):(.text+0x1932): more undefined references to `_MCF_mutex_unlock_slow' follow
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0xb): undefined reference to `_MCF_tls_key_new'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x4c): undefined reference to `_MCF_once_wait_slow'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x6c): undefined reference to `__MCF_gthr_call_once_seh_take_over'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0xc7): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0xde): undefined reference to `__MCF_tls_table_get'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x1f0): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x211): undefined reference to `__MCF_tls_table_xset'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x30a): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x331): undefined reference to `__MCF_tls_table_xset'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x3e1): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x3fd): undefined reference to `__MCF_tls_table_get'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x41f): undefined reference to `__MCF_tls_table_xset'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x469): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x48c): undefined reference to `__MCF_tls_table_xset'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x5b2): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x5c9): undefined reference to `__MCF_tls_table_get'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x69c): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x6b3): undefined reference to `__MCF_tls_table_get'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x7e2): undefined reference to `_MCF_thread_self'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/q0h11ca8sn2vzakjqa3sp2yqp6srmp6g-i686-w64-mingw32-gcc-15.2.0/lib/gcc/i686-w64-mingw32/15.2.0/libgcc_eh.a(unwind-sjlj.o):(.text+0x7f9): undefined reference to `__MCF_tls_table_get'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

It appears that the errors are the same when I add
pkgs.pkgsCross.mingw32.buildPackages.glibc.static or pkgs.pkgsCross.mingw32.buildPackages.musl to packages.
Why? What does -L do differently compares to -C link-arg=-Wl,-rpath?

The -L flag adds the specified path to the locations that the linker will search for at linking time to find libraries, whereas -rpath sets the locations that the dynamic loader will search at runtime to find dynamically linked libraries. Microsoft Windows also does not use the rpath, it is only used on unix like systems.

I see

I’ve successfully compiled the crate. Apparently I needed

pkgs.pkgsCross.mingw32.windows.pthreads
pkgs.pkgsCross.mingw32.windows.mcfgthreads
pkgs.pkgsCross.mingw32.windows.mingw_w64

And I need to add “some” files to link manually via

env.RUSTFLAGS =
  let
    libdirs = [
      pkgs.pkgsCross.mingw32.windows.pthreads
      pkgs.pkgsCross.mingw32.windows.mcfgthreads
      pkgs.pkgsCross.mingw32.windows.mingw_w64
    ]
    libnames = [
      "libmcfgthread.a" # A library from mcfgthreads
      
      # + 464 libraries from mingw_w64
    ];
  in
  lib.concatStringsSep " "
  (
    (map (a: "-L ${a}/lib") libdirs) # The directory to search for library for
    ++ (map (a: "-Clink-arg=-Wl,-l:${a}" libnames) # The libraries to link against
  );

I can’t be bothered to figure out what library is needed from mingw_w64 so I wrote every single library name into the config. Is there a better way? Some automatic tools perhaps? Or a link argument that let me input a directory instead of a single file?

I think this happens because Rust uses pthreads, but nix’s gcc uses mcfgthreads, so it needs to be added manually. I inspected the compiled dll and it did not appear to depend on pthreads.

This is one way I got it to compile, another was patching threadsCross in gcc. I had to take libunwind from MYSY2as I could not get the version in nixpkgs to work.

{ pkgs ? import <nixpkgs> {} }:
let
  rustupToolchain = "1.93.0";
  rustBuildTargetTriple = "i686-pc-windows-gnu";
  rustBuildHostTriple = "x86_64-unknown-linux-gnu";
  pkgsCross = pkgs.pkgsCross.mingw32;
  libunwind = pkgs.fetchzip {
    url = "https://mirror.msys2.org/mingw/mingw32/mingw-w64-i686-libunwind-21.1.8-1-any.pkg.tar.zst";
    hash = "sha256-ryNToG2qUyAMi9ZRuXXNO5oWdWO7YWGQcjwv3ZCWj7E=";
    nativeBuildInputs = [ pkgs.zstd ];
    stripRoot=false;
  };
in
pkgs.mkShell rec {
  nativeBuildInputs = with pkgs; [
    rustup
    pkgsCross.buildPackages.gcc
  ];

  RUSTUP_HOME = toString ./.rustup;
  CARGO_HOME = toString ./.cargo;
  RUSTUP_TOOLCHAIN = rustupToolchain;
  CARGO_BUILD_TARGET = rustBuildTargetTriple;

  shellHook = ''
    export PATH=$PATH:${CARGO_HOME}/bin
    export PATH=$PATH:${RUSTUP_HOME}/toolchains/${rustupToolchain}-${rustBuildHostTriple}/bin/
    rustup target add "${rustBuildTargetTriple}"
  '';

  RUSTFLAGS = [ "-C" "link-args=-lmcfgthread -lunwind" ] ++ (builtins.map (a: ''-L ${a}/lib'') [
    pkgsCross.windows.pthreads
    pkgsCross.windows.mcfgthreads
    "${libunwind}/mingw32"
  ]);
}

pkgsCross.buildPackages.gcc is already aware of mingw_w64, so this should not need to be done.

This is what the linker error looks like without manually linking libraries from mingw_w64

error: linking with `i686-w64-mingw32-gcc` failed: exit status: 1
  |
  = note:  "i686-w64-mingw32-gcc" "-Wl,/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustczYB5F7/list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-Wl,--large-address-aware" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "<1 object files omitted>" "-Wl,-Bstatic" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/rustczYB5F7/{libgetrandom-947e89f60f2cc42c,liblibloading-a769ad0c16c890d6,libstd-0fc6e6dc4cfbd353}.rlib" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libcompiler_builtins-207f8ff316aafd61.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lkernel32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-ldbghelp" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmingwex" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-L" "/nix/store/a1hjv7q257wlf0ixf8i8jbnfg51xqwsh-mingw_w64-pthreads-i686-w64-mingw32-13.0.0/lib" "-L" "/nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib" "-L" "/nix/store/idisv8js5x6kbsgq30zribx25capp49c-mingw-w64-i686-w64-mingw32-13.0.0/lib" "-o" "/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/ewext.dll" "-Wl,--gc-sections" "-shared" "-Wl,--out-implib=/home/peach/code-projects/noita_entangled_worlds/ewext/target/i686-pc-windows-gnu/release/deps/libewext.dll.a" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "-Wl,-l:libmcfgthread.a" "<sysroot>/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_mutex.c.obj):(.text$_MCF_mutex_lock_slow+0x561): undefined reference to `_imp__NtWaitForKeyedEvent@16'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_mutex.c.obj):(.text$_MCF_mutex_lock_slow+0x743): undefined reference to `_imp__NtWaitForKeyedEvent@16'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_once.c.obj):(.text$_MCF_once_wait_slow+0x15c): undefined reference to `_imp__NtWaitForKeyedEvent@16'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_once.c.obj):(.text$_MCF_once_wait_slow+0x2b7): undefined reference to `_imp__NtWaitForKeyedEvent@16'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_thread.c.obj):(.text$__MCF_thread_attach_foreign+0x90): undefined reference to `_imp__NtDuplicateObject@28'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_thread.c.obj):(.text$_MCF_thread_drop_ref_nonnull+0x53): undefined reference to `_imp__NtClose@4'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_msize+0x1e): undefined reference to `_imp__HeapSize@12'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_initialize_winnt_timeout_v3+0xeb): undefined reference to `_imp__QueryUnbiasedInterruptTime@4'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_adjust_winnt_timeout_v3+0x2c): undefined reference to `_imp__QueryUnbiasedInterruptTime@4'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_batch_release_common+0x5c): undefined reference to `_imp__NtReleaseKeyedEvent@16'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_batch_release_common+0x8f): undefined reference to `_imp__RtlDllShutdownInProgress@0'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_gthread_initialize_globals+0xbd): undefined reference to `_imp__GetModuleHandleExW@12'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_gthread_initialize_globals+0xee): undefined reference to `_imp__GetModuleHandleExW@12'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_gthread_initialize_globals+0x1b1): undefined reference to `_imp__EncodePointer@4'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_gthread_initialize_globals+0x23b): undefined reference to `_imp__BaseGetNamedObjectDirectory@4'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_gthread_initialize_globals+0x2ce): undefined reference to `_imp__NtCreateSection@28'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_gthread_initialize_globals+0x3a8): undefined reference to `_imp__NtMapViewOfSection@40'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_gthread_initialize_globals+0x401): undefined reference to `_imp__NtUnmapViewOfSection@8'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_xglobals.c.obj):(.text$__MCF_gthread_initialize_globals+0x41f): undefined reference to `_imp__NtClose@4'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_fwd.c.obj):(.text$__MCF_runtime_failure+0x433): undefined reference to `_imp__NtRaiseHardError@24'
          /nix/store/8fzv58m3yvsq1rynmv7qlgzp1gmap16d-i686-w64-mingw32-binutils-2.44/bin/i686-w64-mingw32-ld: /nix/store/gic00xs26dkkjg7f9fm5s072rgnjansk-mcfgthread-i686-w64-mingw32-2.3.1/lib/libmcfgthread.a(mcfgthread_fwd.c.obj):(.text$__MCF_runtime_failure+0x4a1): undefined reference to `_imp__RaiseFailFastException@12'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

I’ll try your solution later. Thanks a lot!

Woke up today and tried.

  RUSTFLAGS =
    let
      dylibs = [
        pkgsCross.mingw32.windows.pthreads
        pkgsCross.mingw32.windows.mcfgthreads
      ];
      searchDirs = map (a: "-L ${a}/lib") dylibs;
    in
    [
      "-C" "link-arg=-lmcfgthread"
    ]
    ++ searchDirs;

This works, perfectly. What’s the difference between -lmcfgthread and -Wl,-l:libmcfgthread.a? It seems like using `-lmcfgthread` let the linker to resolve all other missing symbols issues I’ve came across previously.

With -lmcfgthread you are letting the linker pick which version of the library it uses, whereas with -l:libmcfgthread.a you are explicitly telling it to use the static library.

The library package innixpkgs provides:

  • libmcfgthread-minimal.dll.a
  • libmcfgthread.a
  • libmcfgthread.dll.a

The linker, when using the -lxxx syntax, uses the following precedence for choosing which version of the library to use (reference).

libxxx.dll.a
xxx.dll.a
libxxx.a

Now, using the static version of the library is fine, but the reason it failed in the logs given above was that it could not resolve the symbols provided in libntdll. That library is present, but the reason that the symbols were not found is due to the order of the arguments provided to the command line.

An issue notes that “-C link-arg was usable for overriding options previously passed by the compiler for long time, so is pretty much guaranteed to be passed at the end of command line at this point.”

Instead of using the codegen flag -C, using -lstatic=mcfgthread directly works for me because of the better ordering of the arguments.