I have problems using a shared library that was linked against a shared library. I will show you a minimal example of my problem.
Suppose, I have A.c and A.h and want to generate libA.so like this:
A.h
double test(void);
A.c
#include "A.h"
double test(void) {
return 2.0;
}
Compilation: gcc -shared -o libA.so A.c -fPIC
Now I want to build a shared library libB.so that uses the function test() from libA.so:
B.c
#include "A.h"
double test123(void) {
return test();
}
Compilation: gcc -shared -o libB.so B.c -fPIC -L. -lA
Both compilations work perfectly. LD_LIBRARY_PATH=. ldd libB.so shows libA.so => ./libA.so (0xb7778000) so I assume, that libB.so knows it was linked against libA.so and knows where to look for it. (I wonder why I need LD_LIBRARY_PATH here…)
However, LD_LIBRARY_PATH=. nm libB.so | c++filt shows U test, saying that the symbol test is undefined.
How come? What did I do wrong? Why can the functions of libA.so not be found in libB.so?
Because
libA.soandlibB.soare not the same file.The outcome you observed is exactly the correct and the desired one.
IF you want
test()to be inlibB.so, then you have to put it there. If you want it to come fromlibA.so, then you have already achieved this.