Exit with error if a library/exe/... contains duplicate modules.

Fixes #1483.