My application dynamically loads liba.so
(with dlopen
).liba.so
uses libb.so
so I want to link liba.so
against libb.so
.
How to do this in Linux?
Thanks in advance.
Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries.
Dynamic linking is the most common method, especially on Linux systems. Dynamic linking keeps libraries modular, so just one library can be shared between any number of applications. Modularity also allows a shared library to be updated independently of the applications that rely upon it.
Shared libraries are the most common way to manage dependencies on Linux systems. These shared resources are loaded into memory before the application starts, and when several processes require the same library, it will be loaded only once on the system. This feature saves on memory usage by the application.
If you build liba.so
yourself, you need to link it with -l
option
gcc -o liba.so liba.o -L/libb/path -lb
If you don't have liba
sources, perhaps you could create libawrapper.so
linked against liba
and libb
and to load dynamically this library
gcc -o libawrap.so -L/liba/ -L/libb/ -la -lb
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