Patch for windows

I'm not sure that those changes are compatible with cross compiling for windows.

Also added better logging in case of error