Fixing the build on GNU/Linux. Please report if this breaks the build on other systems. I hope it doesn't.

* "-lpthread" was ignored by GCC resulting in a linking error. Declaring it closer to the other linker parameters fixed the issue.
* There was an #endif misplaced which was improperly including the closing bracket of a switch statement. So when the #ifdef was false, the resulting code would get broken.
* Also the #include "libz/libz.h" was resulting in the header not being found. I switched it to #include <libz.h> so it will look for the file in the system default library include directories.