微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C ++ linux:dlopen无法find.so库

重写的问题(虽然已经解决了):

我一直在使用dlopen(3)在Linux上加载共享库。 这个库是由我构build的一个库系统的一部分,它们都是在运行时由中央可执行文件加载的。 所有这些都在Code :: Blocks中组织成一个工作区,每个项目在一个名为Source的目录中都有自己的文件夹,这个目录将随程序一起提供。 可执行文件的构build目录是两个从它自己的源代码向后的目录,所以exectuable和Source文件夹在同一个目录中,这些库也和可执行文件一样构build到同一个目录,所以自然我就传递了这个库的名字我试图打开如图所示:

int main(int argc,char** argv) { void* hLibrary = dlopen("libLibrary.so",RTLD_Now | RTLD_GLOBAL); if(hLibrary == NULL) { fprintf(stderr,"%sn",dlerror()); return 1; } return 0; }

当构build目录与源代码相同时,这一点起作用,直到我将源代码的目录改变为上述安排。 现在的问题是dlerror()返回“无法打开libLibrary.so:没有这样的文件或目录”,即使该文件显存在并且与可执行文件在同一目录中。 然后我尝试传入“/libLibrary.so”,因为根据dlopen(3)上的手册页,添加/表示相对目录。 这返回了同样的错误

解决这个问题的方法是需要一个“./” – “”。 表示可执行文件的工作目录 – 并且需要在Code :: Blocks中将工作目录更改为可执行文件的构build目录。 以下作品完美:

device_create与现有的设备名称

WH_MOUSE_LL钩子不会被调用注入事件(mouse_event,sendinput

麻烦使用pthread_mutex_lock

在“perf”事件中捕获用户空间variables

在Windows关机时,Windows服务如何运行?

void* hLibrary = dlopen("./libLibrary.so",RTLD_Now | RTLD_GLOBAL);

这并不能真正显示完整的解决scheme,但以下基本上与我正在做的事情相同:

void* hLibrary = dlopen("./../../libLibrary.so",RTLD_Now | RTLD_GLOBAL);

希望这可以更好地解释情况。

模块句柄通过基地址

如何计算给定date的星期数?

Linux(GLNXA64)使用mxCreateUninitNumericMatrix R2013b

在dup赛后安全吗?

Nginx提供C ++ cgi脚本:响应是二进制格式

阅读dlopen(3)手册页(例如,通过在机器上的终端键入man dlopen ):

如果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) ,它希望你的插件在/usr/lib/ etc中的$LD_LIBRARY_PATH中。 – 或添加. 到您的LD_LIBRARY_PATH (我不建议出于安全原因)。

正如Jhonnash回答你应该使用并显示dloror (或dlsym )失败时的结果:

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

您可能需要阅读“ 高级Linux编程”等书籍,以获得有关Linux系统编程的一些知识。

关于dlopen的定义; 动态库dlopen错误可以被检查。 未定义的符号错误通过此链接

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐