Fix linking on Windows

This fixes a dynamic linking error when building on Windows with `mingw`.

I am not an autotools expert so please review this carefully.