Reputation: 553
I'm interested how does linux act in situation that pictured.
You can see library "A" is staticaly linked with application. But this application depends on dynamic library B, and it in turn depends on library A.
So, what library A will use dynamic library B? Staticaly linked library A in my application or it will again load additional library A.
It's important in case if these libraries have different versions.
Also you can suggest me some articles about me, cause for me linker is like black box.
Upvotes: 0
Views: 197
Reputation: 1
Dynamically linked library B libB.so
-which should be dynamically linked, when libB.so
is built, to libA.so
will not see the statically linked libA.a
(even worse, it might have duplicate global variables of that library, so that could give you a nightmare).
Actually, libA.a
does not exist in the ELF executable of your main program. Only some but not all object files a*.o
from libA.a
are statically linked inside your executable (those actually needed).
See Levine Linkers and Loaders book, wikipage on dynamic linking and on ELF, and Drepper's paper How To Write Shared Libraries. See also ld.so(8), ldconfig(8), ldd(1), dlopen(3), mmap(2), proc(5) man pages. Use strace
, and try once cat /proc/self/maps
...
In short avoid linking both statically and dynamically the same library (even of similar or different versions).
Rule of thumb: always link dynamically, except when you know what you are doing and why...
Upvotes: 1