Let be an executable C.exe depending on libB.so that itself depends on libA.so. C.exe doesn’t use libA directly. The tool ldd shows that C.exe still need libA.so :
> ldd C.exe
libB.so => ./libB.so (0x00002b11cc4f5000)
libA.so.1 => ./libA.so.1 (0x00002b11cc719000)
<snip>
I would have thought that libA.so would show up only when inspecting libB.so. Is there a way to avoid that behavior or do you consider it correct ?
My problem is that libA can be updated to version 2 and thus the library name would change to libA.so.2. I recompiled libB but not C.exe. I was expecting C.exe to run fine because it depends on libB which knows which libA to choose, but it is not the case.
How to handle that case ?
Compilation and Linking details
libA.so is compiled and linked this way:
g++ -fPIC -Wall -shared -Wl,-soname,libA.so.1 libA.cpp -o libA.so.1
ln -s libA.so.1 libA.so
libB.so is compiled and linked this way:
g++ -fPIC -Wall -shared -L. -lA libB.cpp -o libB.so
C.exe is compiled and linked this way:
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
g++ -fPIC -Wall -L. -lB exeC.cpp -o C.exe
You’d have to create libA as a static library (using
ar). That way its code will be embedded into libB.so and you won’t have the additional dependencies.