I want dlopen() every shared library in a specific directory. In order to do that,
what is the cleanest way to retrieve linux’s library search path. Or Is there a quicker way of find a specific directory in that path ?
posix would be better.
I want dlopen() every shared library in a specific directory. In order to do
Share
POSIX does not support a mechanism to find out the directories on the shared library search path (it does not mandate
LD_LIBRARY_PATH, for example), so any solution is inherently somewhat platform specific.Linux presents some problems because the values to be used could be based on the contents of
/etc/ld.so.confas well as any runtime value inLD_LIBRARY_PATHenvironment variable; other systems present comparable problems. The default locations also vary by system – with/liband/usr/libbeing usual for 32-bit Linux machines but/lib64and/usr/lib64being used on at least some 64-bit machines. However, other platforms use other locations for 64-bit software. For example, Solaris uses/lib/sparcv9and/usr/lib/sparcv9, for example (though the docs mention/lib/64and/usr/lib/64, they’re symlinks to thesparcv9directories). Solaris also has environment variablesLD_LIBRARY_PATH_64andLD_LIBRARY_PATH_32. HP-UX and AIX traditionally use other variables thanLD_LIBRARY_PATH—SHLIB_PATHandLIBPATH, IIRC — though I believe AIX now usesLD_LIBRARY_PATHtoo. And, on Solaris, the tool for configuring shared libraries is ‘crle’ (configure runtime linking environment) and the analog of/etc/ld.so.confis either/var/ld/ld.configor/var/ld/64/ld.config. Also, of course, the extensions on shared libraries varies (.so,.sl,.dylib,.bundle, etc).So, your solution will be platform-specific. You will need to decide on the the default locations, the environment variables to read, and the configuration file to read, and the relevant file extension. Given those, then it is mainly a SMOP – Simple Matter Of Programming:
opendir())readdir()) in turndlopen()on the path of the relevant files.dlclose()closedir()See also the notes in the comment below…the complete topic is modestly fraught with variations from platform to platform.