如何动态加载具有相同名称但在Linux中不同目录中的库? [英] How to dynamic load the library with same name but in different directory in Linux?
问题描述
我必须在Linux中动态加载.so,但是我发现很难处理相同的名称库. 我在不同的目录中有2个libtest.so,它们依赖于其他不同的库. 我的程序读取配置文件来决定加载哪个libtest.so.例如:
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
它们都未在ldconfig中注册. 那么如何使用dlopen加载不同版本的libtest.so?我希望它们不会相互冲突,因为它们可能依赖于相同或不同的其他库.看来在我的程序中使用putenv/setenv更改LD_LIBRARY_PATH无效.
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.
推荐答案
较新版本的Glibc提供了 dlmopen :
Newer versions of Glibc provide dlmopen for this:
h = dlmopen(LM_ID_NEWLM, "path/to/some/version/of/libtest.so", RTLD_LAZY);
这篇关于如何动态加载具有相同名称但在Linux中不同目录中的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!