栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

C ++ Linux:dlopen找不到.so库

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C ++ Linux:dlopen找不到.so库

阅读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回答的那样,您应该使用并显示

dlerror
when
dlopen
(或
dlsym
)失败的结果:

  void* dlh = dlopen("./libLibraryName.so", RTLD_NOW);  if (!dlh)     { fprintf(stderr, "dlopen failed: %sn", dlerror());       exit(EXIT_FAILURE); };

您可能需要阅读《高级Linux编程》等书籍,以大致了解有关Linux系统编程的知识。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/369290.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号