阅读dlopen(3)手册页(例如,通过
mandlopen在计算机上键入终端):
如果filename包含斜杠(“
/”),则将其解释为(相对或绝对)路径名。否则,动态链接程序将按以下方式搜索库(有关更多详细信息,请参见ld.so(8)):
o (ELF only) If the executable file for the calling program contains a DT_RPATH tag, and does not contain a DT_RUNPATH tag, then the directories listed in the DT_RPATH tag are searched. o If, at the time that the program was started, the environment variable LD_LIBRARY_PATH was defined to contain a colon-separated list of directories, then these are searched. (As a security measure this variable is ignored for set-user-ID and set-group-ID programs.) o (ELF only) If the executable file for the calling program contains a DT_RUNPATH tag, then the directories listed in that tag are searched. o The cache file /etc/ld.so.cache (maintained by ldconfig(8)) is checked to see whether it contains an entry for filename. o The directories /lib and /usr/lib are searched (in that order).
因此,您需要调用
dlopen("./libLibraryName.so",RTLD_NOW)-而不是只dlopen("libLibraryName.so",RTLD_NOW)希望将其插入您的插件中$LD_LIBRARY_PATH,
/usr/lib/等等....-或添加
.到您的插件中
LD_LIBRARY_PATH(出于安全原因,我不建议这样做)。
正如Jhonnash回答的那样,您应该使用并显示
dlerrorwhen
dlopen(或
dlsym)失败的结果:
void* dlh = dlopen("./libLibraryName.so", RTLD_NOW); if (!dlh) { fprintf(stderr, "dlopen failed: %sn", dlerror()); exit(EXIT_FAILURE); };您可能需要阅读《高级Linux编程》等书籍,以大致了解有关Linux系统编程的知识。



