dlopen失败:无法打开共享对象文件:没有这样的文件或目录 [英] dlopen failed: cannot open shared object file: No such file or directory

查看:1732
本文介绍了dlopen失败:无法打开共享对象文件:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我使用dlopen加载了一个库(.so是我写的,它不是系统库),但是标题中显示了错误.

The problem is I use dlopen to load a library (the .so is written by me, it's not a system library), but I got the error shown in the title.

  1. 我已包含dlfcn.h
  2. 在编译器中,我使用了-ldl命令
  3. 我要加载的只是源代码文件夹,我尝试添加-L.,但是没有用.
  1. I have included dlfcn.h
  2. in compiler, I used the -ldl command
  3. What I want to load is just the source code folder, I tried to add -L., but it did not work.

推荐答案

如果要dlopen的库不在标准搜索路径中,则有很多选择:

If the library you want to dlopen is not in the standard search path you have a number of options:

  1. 在dlopen中指定文件的完整路径

  1. Specify the full path to the file in dlopen

dlopen("/full/path/to/libfile.so");

通过LD_LIBRARY_PATH将路径添加到库

Add the path to the library via LD_LIBRARY_PATH

LD_LIBRARY_PATH=/path/to/library/ ./executable

使用ld -rpath选项向应用程序添加库路径.

use the ld -rpath option to add a library path to the application.

g++ -link stuff- -Wl,-rpath=/path/to/library/

请注意,选项1& 3将库路径硬编码到您的应用程序中. -rpath确实具有指定相对路径的选项,即

Note that options 1 & 3 hardcode the library path into your application. -rpath does have an option to specify a relative path, i.e.

-Wl,-rpath=$ORIGIN/../lib/

将相对路径嵌入到应用程序中.

Will embed a relative path into the application.

这篇关于dlopen失败:无法打开共享对象文件:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆