Reputation: 61
If I'm using a shared library in linux, why do I need to link it with -l if the application has to find the library at runtime?
Couldn't I just pass in a dummy .so with the proper function signatures during the linking step and replace it with a real .so at runtime and still have it work properly?
Is there a way to compile an application with just a header file and have the linking take place at runtime?
Upvotes: 1
Views: 182
Reputation: 798746
If I'm using a shared library in linux, why do I need to link it with -l if the application has to find the library at runtime?
So that the loader knows which libraries have to be loaded at runtime.
Couldn't I just pass in a dummy .so with the proper function signatures during the linking step and replace it with a real .so at runtime and still have it work properly?
Absolutely.
Is there a way to compile an application with just a header file and have the linking take place at runtime?
Yes, but then it's your responsibility to call dlopen(3)
and dlsym(3)
yourself to load the libraries and functions.
Upvotes: 2