I've a program that I must build. The program depends on libA
, and libA
depends on libB
. Both libs are in the same folder but ldd libA.so
does not include libB.so
so I must add it while linking it.
This is my gcc
command:
gcc -L/path/to/libraries/lib -lA -lB -I/path/to/libraries/include main.cpp
The program builds and links, but it does not start. It gives me following error:
./a.out: symbol lookup error: /path/to/libraries/lib/libA.so: undefined symbol: symbol_used_in_libA_but_defined_in_libB
With ldd
I can see that libB.so
is not included in my binary:
linux-vdso.so.1 => (0x00007fffaecd9000)
libA.so => /path/to/libraries/lib/libA.so (0x00007effc02a4000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007effbfebb000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007effbfca5000)
/lib64/ld-linux-x86-64.so.2 (0x00007effc05cb000)
I have these conditions:
/path/to/libraries
is inside LD_LIBRARY_PATH
- running
ldconfig
is ok and ldconfig -p
find both libA.so
and libB.so
- If in gcc command I change
-lB
with -lBB
it gives me a linker error, so I think that gcc
find correctly libB.so
even if it does not link it inside the executable.
What I'm doing wrong? What I can do in order to link the executable to both libraries?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…