Fix various compiling problems in OSX