Compilation fixes for mingw

This enables cross-compilation as well as native builds.