How to build a shared library (.so) without hardcoded full dependency paths?

前端 未结 6 1599
面向向阳花
面向向阳花 2020-12-29 07:37

I need to build two 3rd party shared libraries, so their .so files will be reused by other projects. However, after build one of these libraries contains hardcoded path to a

6条回答
  •  情话喂你
    2020-12-29 07:59

    When I run ldd libB.so it gives:

    libA.so.2 => /home/alex/dev/A-install/lib/libA.so.2

    The low-level solution to this problem is to use the option "-soname=libA.so" when you link the libA.so library. By having SONAME defined for a shared object, the linker will not embed absolute paths when linking against that shared object.

    The OP is using "configure", so this isn't an easy solution to implement unless he is willing to go into the bowels of the Makefile generated by the configure script.

提交回复
热议问题