How to dynamic load the library with same name but in different directory in Linux?

你离开我真会死。 提交于 2019-12-08 02:20:16

问题


I have to dynamic load .so in Linux, but I find it is difficult to deal with the same name libraries. I have 2 libtest.so in different directories and they are depend on other different libraries. My program read config file to decide to load which libtest.so. For example:

/usr/kyle/v1/libtest.so
/usr/kyle/v2/libtest.so

They are all not registered in ldconfig. So how can I load different version of libtest.so using dlopen? I hope that they will not be conflict with each other, because they may be depend on same or different other libraries. It seems that change LD_LIBRARY_PATH using putenv/setenv in my program does not work.


回答1:


Newer versions of Glibc provide dlmopen for this:

h = dlmopen(LM_ID_NEWLM, "path/to/some/version/of/libtest.so", RTLD_LAZY);


来源:https://stackoverflow.com/questions/16525016/how-to-dynamic-load-the-library-with-same-name-but-in-different-directory-in-lin

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