'How to build a shared object (.so) with missing dependencies

I would like to build a shared object (let's name it A) that depends on another .so (let's name it B). B is implementing some interface that A is using.

The machine that will load A also has B so when loading A (at load time or via dlopen), it loads B and everything is fine. The issue is that I cannot build B (on the machine I am building A) and therefore cannot build A, since I get a linker error. of course I expect to see B as dependency when doing 'ldd A'.

Is there a linker option to build A without having B?

a picture to visualize my system

Thanks



Solution 1:[1]

The issue is that I cannot build B (on the machine I am building A) and therefore cannot build A, since I get a linker error.

There is a lot of missing info here.

  1. You have a version of B.so somewhere. Why can't you copy that version onto the machine on which you are building A.so, and use it to actually build A.so ?
  2. With default linker flags, you should be able to link A.so even though it uses symbols from B.so without having B.so available (unresolved symbols are ignored by default when building with -shared).

    This will produce A.so which doesn't depend on B.so. At dlopen() time you will simply have to load B.so with RTLD_GLOBAL before loading A.so.
  3. If you really need to have the A.so -> B.so dependency, you can create an empty B.so and link against that.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Employed Russian