OS X build

This allows the library to build on Mac OS X (10.7 tested).  The tests may not build since I haven't tried those yet.

I also fixed a lot of build warnings, some of which could lead to serious problems on 64-bit archs.