问题描述
说我有一个库libfoo.so.1
,该库(根据ldd
)取决于libbar.so.1
.但是,libbar.so.1
目前不可用.我的应用程序需要在libfoo.so.1
中调用一个完全不需要libbar.so.1
的函数.
Say I have a library libfoo.so.1
, which depends (according to ldd
) on libbar.so.1
. However, libbar.so.1
is not available at the moment. My app needs to call a function in libfoo.so.1
which doesn't require libbar.so.1
at all.
是否可以加载libfoo.so.1
,解析功能符号然后在没有libbar.so.1
的情况下调用它来满足依赖关系?这是我知道我在做什么,就让我已经在做"的情况.我尝试了RTLD_LAZY标志,但是它仍然尝试在 not 加载符号之前先加载libbar.so.1
库.
Is there a way to load libfoo.so.1
, resolve the function symbol and then call it without having libbar.so.1
to satisfy the dependency? It's a case of "I know what I'm doing, just let me do it already". I tried the RTLD_LAZY flag, but it still tries to load the libbar.so.1
library before not loading the symbols.
编辑
这是确切的情况.
我们有3位玩家:
-
libbar.so.1
,这是一个位于LD_LIBRARY_PATH
或ldconfig
之外的路径中的共享库,并且所有依赖项都已解决 -
libfoo.so.1
,这是一个共享库,位于与libbar
不同的目录中,但是依赖于libbar
.在运行时,libfoo
会知道libbar
的位置. -
App
,一个二进制应用程序,需要在运行时的某个时刻加载libfoo
.
libbar.so.1
, a shared library located in a path not inLD_LIBRARY_PATH
orldconfig
, and whose dependencies are all resolvedlibfoo.so.1
, a shared library located in a different directory thanlibbar
, but which depends onlibbar
. At runtime,libfoo
will know where to locatelibbar
.App
, a binary application which needs to loadlibfoo
at some point during runtime.
App
不知道在哪里找到libbar
,但是知道libfoo
知道.我要完成的工作是在libfoo
中具有一个init函数,该函数将简单地将App
的当前工作目录更改为libbar
所在的目录,以最终解决所有依赖关系并使所有人满意.
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
最终将 需要调用libbar
中的内容,只是不需要在此init函数中调用.我不认为创建存根会起作用,因为符号最终将需要解析为 real 函数.
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.
推荐答案
好吧,即使使用RTLD_LAZY
,变量仍然可以解析,因此通常您需要链接所有库.似乎您应该创建一个没有功能且可由链接程序找到的存根libbar.so.1
.
Well, variables are still resolved even with RTLD_LAZY
, so in general you do need all the libraries to be linked. Seems like you should create a stub libbar.so.1
that has no functionality and can be found by the linker.
这篇关于如何在不加载依赖库的情况下加载共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!