Mingw build fix

All of these fixes were required to build on MinGW cross compiler on Debian.