How to load a shared library without loading its dependencies?

孤街浪徒 提交于 2019-12-03 05:37:54

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.

Just a thought, have you thought of interpositioning dependency - simply create a identical function with the same signature, parameters etc and let the linker resolve this function and ignore libbar.so.1? Since you did not mention this, I thought I'd suggest this.

Hope this helps, Best regards, Tom.

Another thought: Would extracting (use ar(1)) the necessary function(s) from libfoo.so.1, either into a .o or into another .so file, and then linking against that extract help? I'm assuming the reference to libbar.so.1 is in a libfoo function that is not called (even indirectly) from your program.

What's the actual requirement here? Merely linking a library doesn't do much, and is usually benign. Do you lack the library? Just create a stub library of the same name. You want to control or preempt the use of symbols in the library? Put them in another library (with the right version tags!) and LD_PRELOAD it.

I guess the meta-question here is that I don't see what value being able to preempt the dependency linkage has. It's just a helper function.

Use dlopen to load the library and dlsym to get the function you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!