Libraries exist with a well defined compiler. The solution is at the compiler level, using information coming from the import graph that exists in languages with a module system.
And I'm not sure how you can forget to import a library and still expect to use it, assuming your language has a module system.
C and C++ can't solve this problem, of course, due to textual inclusion.
> The solution is at the compiler level, using information coming from the import graph that exists in languages with a module system.
no, it isn't because your library has to integrate with other languages when you make native stuff. I should be able to call dlopen from any native language without having to care in which language your library was implemented, just calling my OS's dlopen / LoadLibrary OS API function should be enough. If this doesn't work, then your solution is just not acceptable in many cases, so yes you have to work with its limits.