Fix windows static build

Fixes #4478. See commit descriptions for details.