Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to link shared library against other shared library in linux?

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.

like image 733
dragan.stepanovic Avatar asked Sep 02 '10 09:09

dragan.stepanovic


People also ask

How are shared libraries linked?

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.

What is dynamic link libraries in Linux?

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.

How does shared library work in Linux?

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.


1 Answers

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
like image 200
Dmitry Yudakov Avatar answered Sep 25 '22 18:09

Dmitry Yudakov