c++linuxlinkershared-libraries

Force symbols to resolve when creating shared library


I am creating a shared library (.so), which contains my code, plus some third-party .so's. Specifically, one of the third-party .so's is libaide.so.

After linking, when I do a nm -DC mylib.so, I see that all symbols from libaide.so are undefined ("U" in nm output). Now, I can resolve them when I create the final executable, by linking with libaide.so at the final compile/link, but I would like to give mylib.so to others, and not require them to add -laide to their final linking step.

Is this even possible? How do I do this?


Solution

  • AFAIK there are two ways.

    The first is to use -Wl,-unresolved-symbols=ignore-in-shared-libs for all the intermediate steps, which ignores unresolved symbols in shared libs.

    The second is to produce a stub shared library for intermediate steps, which has the same apis as your mylib.so, but all the implementations are fake so that the stub does not depend on libaide.so. And when running, you should use the real mylib.so.

    Both ways need libaide.so present when running.