How to dynamic load the library with same name but

2019-05-28 14:07发布

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条回答
叛逆
2楼-- · 2019-05-28 14:44

Newer versions of Glibc provide dlmopen for this:

h = dlmopen(LM_ID_NEWLM, "path/to/some/version/of/libtest.so", RTLD_LAZY);
查看更多
登录 后发表回答