c++ - Dynamic Linking of Shared Libraries with Dependencies -
is there way dynamically link shared libraries have dependencies?
for example, have 2 libraries, liba.so , libb.so. libb.so calls functions defined in liba.so.
in main program, wish load 2 libraries dlopen. however, if try:
dlopen(liba.so); dlopen(libb.so);
then sec dlopen fail libb has unrecognized symbols.
i can think of few workarounds such building object files single shared library, or have libb.so phone call dlopen on liba.so, that's work.
i guess way i'm imagining work in case of kernel modules can utilize "export_symbol()" allow other modules phone call functions defined in loaded module.
can similar done shared libraries? or have utilize workarounds?
i experienced similar situation, worked me (using gcc toolchain):
when create shared object libb.so
, unconditionally link library liba.so
, command should this:
gcc -shared -wl,--no-as-needed -la -o libb.so b.o
you can check liba.so
indeed became dependency dynamic linker:
$ ldd libb.so linux-gate.so.1 => (0xb77ba000) liba.so => not found libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb75f7000) /lib/ld-linux.so.2 (0xb77bb000)
in main programme should sufficient dlopen()
library libb.so
, , other library should linked automatically dynamic linker.
c++ c shared-libraries
No comments:
Post a Comment