c - linking two shared libraries with some of the same symbols -
i trying link 2 different shared libraries. both libraries define symbols share name have different implementations. can't seem find way make each library use own implementation on other.
for example, both libraries define global function bar()
each calls internally. library 1 calls foo1()
, library 2 calls foo2()
.
lib1.so:
t bar t foo1() // calls bar()
lib2.so:
t bar t foo2() // calls bar()
if link application against lib1.so , lib2.so bar implementation lib1.so called when calling foo2()
. if on other hand, link application against lib2.so , lib1.so, bar called lib2.so.
is there way make library prefer own implementation above other library?
there several ways solve this:
pass
-bsymbolic
or-bsymbolic-functions
linker. has global effect: every reference global symbol (of function type-bsymbolic-functions
) can resolved symbol in library resolved symbol. lose ability interpose internal library calls symbols using ld_preload. the symbols still exported, can referenced outside library.use version script mark symbols local library, e.g. use like:
{local: bar;};
, pass--version-script=versionfile
linker. the symbols not exported.mark symbols approppiate visibility (gcc info page visibility), either hidden, internal, or protected. protected visibility symbols are exported
.protected
, hidden symbols not exported, , internal symbols not exported , compromise not call them outside library, indirectly through function pointers.
you can check symbols exported objdump -t
.
Comments
Post a Comment