void *dlopen(const char *filename, int flag);
The dlopen()
loads the dynamic library file named by the null-terminated string filename
and returns an opaque "handle" for the dynamic library. If the library has dependencies on other shared libraries, then these are also automatically loaded by the dynamic linker, recursively.
So, whatever be the case a standard dlopen()
will never prepend or do any modification to the filename
string.
The specified filename is searched in the following manner:
(ELF only) If the executable file for the calling program contains a
DT_RPATH
tag, and does not contain aDT_RUNPATH
tag, then the directories listed in theDT_RPATH
tag are searched.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.)(ELF only) If the executable file for the calling program contains a
DT_RUNPATH
tag, then the directories listed in that tag are searched.The cache file
/etc/ld.so.cache
(maintained by ldconfig(8)) is checked to see whether it contains an entry for filename.The directories
/lib
and/usr/lib
are searched (in that order).
So, this strange behavior that you notice for dlopen() might possibly be due to an existing symlinks/hardlinks to the library librdmacm.so
and libibverbs.so
as rdmacm.so
and ibverbs.so
, in any of the above mentioned library search paths.
If dlopen()
fails for any reason, it returns NULL. Check for NULL before using the handle returned by dlopen
.
handle = dlopen("libxyz.so", RTLD_LAZY);
if (!handle)
{
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
Refer: man 3 dlopen