Gcc build links but shared library not showing with ldd

I have a program that I have to create. The program depends on libA, but libAdepends on libB. Both libraries are in the same folder, but ldd libA.sonot included libB.so, so I have to add it by linking it.

This is my command gcc:

gcc -L / path / to / libraries / lib -lA -lB -I / path / to / libraries / include main.cpp

The program builds and binds, but it does not start. This gives me the following error:

./a.out: symbol search error: /path/to/libraries/lib/libA.so: undefined symbol: symbol_used_in_libA_but_defined_in_libB

C lddI see that it is libB.sonot 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 the following conditions:

  • /path/to/libraries is inside LD_LIBRARY_PATH
  • running ldconfig ldconfig -p libA.so, libB.so
  • gcc -lB -lBB, , , gcc libB.so, .

? , ?

+4
1

Linux ( , Linux ldd), -, gcc --as-needed ld (, . Debian). , / (.. DT_NEEDED ), - / .

main.cpp libB, libB . , --no-as-needed . .

gcc -Wl, - no-as-needed...

, , libA , libB .

+6

All Articles