Fix build on MinGW

This is a really quick and dirty set of fix to get it to build & link.
There's probably a much better way to handle all these issues, which mostly stem from the fact that 4e002d9a92ecd7cec0fb98b0bedbace8aad81f6e isn't portable as-is.

I haven't tried the feature in question, and completely forgot to run the test suite, so, here be dragons!