Make accessing undefined variables an error (instead of a warning).

Fixes #5809
Make duplicate object definitions an error.

Fixes #3638
Add missing #include.