scan#

Find the shared libraries in a list of directories.

Synopsis#

my $libs = Peta::FFI::scan;
print $libs->{"libm.so.6"}, "\n";         # /usr/lib/libm.so.6
my @names = grep { /^libssl/ } keys %$libs;

my $ours = Peta::FFI::scan("/opt/PetaTech/lib");
my $core = Peta::FFI::dlopen($ours->{"libpeta_core.so"});

What you get back#

A hashref mapping each library’s file name to its path: every lib*.so and lib*.so.* file in the directories searched that this process can load - an ELF file of its own architecture. A linker script (/usr/lib/libc.so is one), a 32-bit library on a 64-bit system and any other file are left out. A name found in more than one directory maps to the first one’s file.

Where it looks#

  • scan(@dirs) - those directories, in that order, and no others.

  • scan() - the directories in PETA_FFI_PATH (colon-separated, like PATH), then where the dynamic linker looks for a bare name: LD_LIBRARY_PATH, the directories /etc/ld.so.conf configures and the system’s own (/lib, /usr/lib and their 64-bit forms).

The search happens only here. dlopen with a bare name asks the dynamic linker, which never reads PETA_FFI_PATH; a library installed in a directory of its own is found by scan and opened by the path it returns.

Edge cases#

  • A directory that does not exist or cannot be read - skipped.

  • One directory reached twice (/lib64 is often a link to /usr/lib) - searched once. A library in a system directory is reported under the directory’s real path; one in a directory you named, under the name you gave.