How to force using local shared libraries over system libraries?

拟墨画扇 提交于 2019-11-30 05:04:34

When you link, specify the directory of the library and also use an rpath:

-Wl,-rpath,/absolute/path/to/your/library -L/absolute/path/to/your/library -llibrary

-L tells the linker where to find your library at link time, and -rpath tells it where to search for the library at runtime.

Note that -L and -rpath need the directory that contains your .so file, not the actual path of the library file itself.

I have to question why you want to use your own version of a library over a system-provided version (having multiple different versions floating around is nothing but a recipe for trouble and user confusion).

However, you should be able to export LD_PRELOAD=<path_to_your_shared_obj> to force it to load your own version.

Note that no mechanism to override library versions will persist through any sort of privilege elevation (for example sudo).

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