如何加载共享库而不加载其依赖项?

Fre*_*red 13 c linux shared-libraries elf

说我有一个图书馆libfoo.so.1,依赖于(根据ldd)libbar.so.1.但是,libbar.so.1暂时不可用.我的应用需要调用一个libfoo.so.1根本不需要的功能libbar.so.1.

有没有办法加载libfoo.so.1,解析函数符号然后调用它而不必libbar.so.1满足依赖?这是"我知道我在做什么,只是让我这样做"的案例.我尝试了RTLD_LAZY标志,但它仍然尝试libbar.so.1加载符号之前加载库.


编辑

这是确切的情况.

我们有3名球员:

  • libbar.so.1,共享库位于路径没有LD_LIBRARY_PATHldconfig,且其相关性都得到解决
  • libfoo.so.1, a shared library located in a different directory than libbar, but which depends on libbar. At runtime, libfoo will know where to locate libbar.
  • App, a binary application which needs to load libfoo at some point during runtime.

App doesn't know where to find libbar, but knows that libfoo knows. What I'm trying to accomplish is having an init function in libfoo which would simply change App's current working directory to where libbar is located to finally resolve all the dependencies and make everyone happy.

libfoo will eventually need to call stuff in libbar, just not in this init function. I don't think creating a stub would work since the symbols would eventually need to resolve to the real functions.

Ada*_*ode 4

嗯,即使使用 ,变量仍然可以解析RTLD_LAZY,所以一般来说您确实需要链接所有库。似乎您应该创建一个libbar.so.1没有功能并且可以由链接器找到的存根。