Apply patch from AlexRou. Fix mingw build.