问题
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