Can a static libary *.a
in Linux be dynamically loaded at runtime?
I've read here that
...both static and shared libraries can be used as dynamically loaded libraries.
How to dynamically load static library?
There is nothing like “linking a static library to dynamic library”. “Linking” is a process of completing the “symbol table” present in every executable or a shared library (see “Linkers and symbol tables”).
Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.
Static libraries are either merged with other static libraries and object files during building/linking to form a single executable or loaded at run-time into the address space of their corresponding executable at a static memory offset determined at compile-time/link-time.
A static library must be linked into the final executable; it becomes part of the executable and follows it wherever it goes. A dynamic library is loaded every time the executable is executed and remains separate from the executable as a DLL file.
A static library is more or less just a collection of object files. If you want to use a static library in a program, you have to link the executable with it. The executable will then contain the static library (or the parts that you used).
If you want to load a static library at runtime using dlopen
, you will have to first create a dynamic library libfoo.so
containing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With