Checking that a library name is valid before compilation.

Fixes bug #3333.