- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个使用 infiniband rdmacm 库 rdmacm.so 的程序
在一台计算机(Ubuntu 服务器)上,我可以毫无问题地运行它。在我的开发电脑(Ubuntu 桌面版)上,我得到:
./test-client rdmacm.so: cannot open shared object file: No such file or directory
这就是我被难住的地方。
ldd rdma 客户端
linux-vdso.so.1 => (0x00007fffdb62b000)
libibverbs.so.1 => /usr/lib/libibverbs.so.1 (0x00007f97ca007000)
librdmacm.so.1 => /usr/lib/librdmacm.so.1 (0x00007f97c9dfe000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f97c9a3e000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f97c9821000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f97c961d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f97ca237000)
cat/etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
cat/etc/ld.so.conf.d/*.conf
# Multiarch support
/lib/i386-linux-gnu
/usr/lib/i386-linux-gnu
/lib/i686-linux-gnu
/usr/lib/i686-linux-gnu
# libc default configuration
/usr/local/lib
# Multiarch support
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
/usr/lib/fglrx
/usr/lib32/fglrx
# Legacy biarch compatibility support
/lib32
/usr/lib32
ls -l/usr/lib/librdmacm*
-rw-r--r-- 1 root root 41146 Jul 19 2011 /usr/lib/librdmacm.a
lrwxrwxrwx 1 root root 18 Jul 19 2011 /usr/lib/librdmacm.so -> librdmacm.so.1.0.0
lrwxrwxrwx 1 root root 18 Jul 19 2011 /usr/lib/librdmacm.so.1 -> librdmacm.so.1.0.0
-rw-r--r-- 1 root root 35248 Jul 19 2011 /usr/lib/librdmacm.so.1.0.0
一切看起来都是正确的。为什么我不能运行测试客户端。
编辑
我使用的代码来自 geekinthecorner 博客。 Infiniband 测试应用。
在客户端它有几个 dlopen 调用:
即
void *handle = dlopen("rdmacm.so", RTLD_LAZY);
...
handle = dlopen("ibverbs.so", RTLD_LAZY);
这适用于 ubuntu 服务器。但是在我的开发台式机上它找不到库。
如果我将库重命名为这样
void *handle = dlopen("librdmacm.so", RTLD_LAZY);
...
handle = dlopen("libibverbs.so", RTLD_LAZY);
他们被发现了。 dlopen 不会自动添加“lib”吗?我假设是的,我的服务器上一定是这种情况,因为找到的库没有这个。
无论如何,我不确定我是否需要这些 dlopen 调用。我可以完全删除它们并且程序可以运行。但是,现在我很好奇为什么 dlopen 在两台机器上表现不同,因为路径和/etc/ld.so.conf 设置包含相同的搜索路径。
最佳答案
void *dlopen(const char *filename, int flag);
dlopen()
加载由空终止字符串filename
命名的动态库文件,并为动态库返回一个不透明的“句柄”。如果库依赖于其他共享库,那么动态链接器也会自动递归地加载这些库。因此,无论是哪种情况,标准的 dlopen()
都不会在 filename
字符串前加上或做任何修改。
按以下方式搜索指定的文件名:
(仅限 ELF)如果调用程序的可执行文件包含 DT_RPATH
标记,但不包含 DT_RUNPATH
标记,则列出的目录搜索 DT_RPATH
标签。
如果在程序启动时,环境变量 LD_LIBRARY_PATH
被定义为包含以冒号分隔的目录列表,则会搜索这些目录。 (作为一项安全措施,对于 set-user-ID 和 set-group-ID 程序会忽略此变量。)
(仅限 ELF)如果调用程序的可执行文件包含 DT_RUNPATH
标记,则搜索该标记中列出的目录。
检查缓存文件 /etc/ld.so.cache
(由 ldconfig(8) 维护)以查看它是否包含文件名条目。
搜索目录 /lib
和 /usr/lib
(按此顺序)。
因此,您注意到的 dlopen() 的这种奇怪行为可能是由于库 librdmacm.so
和 libibverbs.so
的现有符号链接(symbolic link)/硬链接(hard link)所致rdmacm.so
和 ibverbs.so
,在上述任何库搜索路径中。
如果 dlopen()
由于任何原因失败,它返回 NULL。在使用 dlopen
返回的句柄之前检查 NULL。
handle = dlopen("libxyz.so", RTLD_LAZY);
if (!handle)
{
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
引用:man 3 dlopen
关于c - rdmacm.so : Cannot open shared object file. 但是,文件存在于库路径中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13872096/
我是一名优秀的程序员,十分优秀!