Resolve various compilation errors and warnings for gcc on Mac and Linux, VC8 to VC10 on Windows.