Building latest master on Windows

You might still have C:\msys64\mingw64 somewhere in your environment variables (PATH, CAMLIBS, IOLIBS…), or CAMLIBS/IOLIBS might be pointing to dt 4.0 installed in C:\Program Files\darktable\... (which has MINGW64 binaries)?

The UCRT64 terminal sets these up for you correctly for that session, that’s why it works.