Quite a few fixes rolled up into one PR

Adds build.sh and clean.sh scripts
Addresses format string bugs in logging in the examples
Detect errors opening the log / prevent writing on failure.
Fixes various compiler warnings