Improve search for dynamic libraries

Now, dynamic libraries are searched in these places:
 1. Current working directory
 2. Current import paths (for example, from loaded packages)
 3. The system paths for dynamic libs

Fixes #861.