Now i have 3 shared objects,A.so,B.so,C.so
A.c
void libA()
{
common();
}
B.c
void common()
{
printf("COME HERE B\n");
}
C.c
void common()
{
printf("COME HERE C\n");
}
(just ingore the .h files)
test.c
int main()
{
libA();
return 1;
}
complie:
gcc -fPIC -shared libB.so libB.c
gcc -fPIC -shared libA.so libA.c ./libB.so
gcc -o test test.c libC.so libA.so
I wish result to be "COME HERE B" and i could use dlopen
with RTLD_DEEPBIND
flag,
but it costs too much time to change functions from implicit call to explicit call in my project.
Is there anyway to solve this problem?
gcc -Wl,-Bsymbolic
doesn't work in this solution.
Well, if A.c contains implementation of common. It does work.
It looks like when the dynamic linker searches for a symbol in runtime, it chooses the first one that it comes across. The search order depends on the order of libraries in DT_NEEDED
section of the binary, which in turn depends on the exact order of libraries in the command line during compilation.
So, make sure libB.so
is before libC.so
on the command line when compiling test.c
.
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