Fix Mac OS build and some compiler warnings

I've tested compilation on Mac OS 10.8.5 and 32-bit Ubuntu. Need to test 64-bit Linux and Windows still, but I don't have those available at the moment.