Fix several build issues to make crosscompilation and w32 happy