NAME
Sys::GNU::ldconfig - Search for shared libraries
SYNOPSIS
use Sys::GNU::ldconfig;
my $libso = ld_lookup( 'k5crypto' ); # /usr/lib64/libk5crypto.so on CentOS 5.8
$libso = ld_lookup( 'libk5crypto' ); # same thing
my $ld = Sys::GNU::ldconfig->new;
$libso = $ld->lookup( 'k5crypto' ); # same again
$libso = $ld->lookup( 'libk5crypto' ); # still the same
DESCRIPTION
Sys::GNU::ldconfig reproduces the logic used by ldconfig and ld.so to find a shared library (.so or .dll). It is intended for modules like PAR::Packer, that repackage code.
Sys::GNU::ldconfig will search the following places in order for a shared library:
- LD_LIBRARY_PATH
-
This is a colon
:
seperated list of directories. Because it is named differently on some systems, ld_lookup uses$Config::Config{ldlibpthname}
. - /etc/ld.so.conf
-
This file contains a list of directories to search. Directories are seperated by comma (
,
), space (:
) or newline (\n
). May also contain an "include" directive, which is a file glob of other config files to include. - Trusted directories
-
/lib64 /lib /usr/lib64 /lib
These directories are hardcoded into ldconfig.
FUNCTIONS
ld_lookup
$so = ld_lookup( 'k5cyrpto' );
$so = ld_lookup( 'libk5cyrpto' );
$so = ld_lookup( 'libk5cyrpto.so.13' );
Find a shared library. Works with the library name (k5crypto
), filename (libk5crypto.so
) or versioned filename (libk5cyrpto.so.13
).
Returns the full path to the major version of the library, for example /usr/lib64/libcurl.so.4
and not the full versioned (/usr/lib64/libcurl.so.4.2.0
or unversioned (/usr/lib64/libcurl.so
).
When first called, ld_lookup creates a list of directories to search. Subsequent calls will reuse this list. The list is cleared by calling "ld_root".
ld_root
ld_root( '/mnt' );
Sets the root directory. Defaults to /
. This is roughly equivalent to doing chroot(2) before calling "ld_lookup". Note that ld_lookup
will return a file path with the root stripped out.
Setting the root directory will clear the list of directories to search.
METHODS
Sys::GNU::ldconfig also provides an object-oriented interface.
new
$ld = Sys::GNU::Lookup->new;
Create an object.
lookup
my $so = $ld->lookup( 'k5cyrpto' );
Find a shared library.
dirs
my @dirs = $ld->dirs;
Returns a list of directories that will be searched for shared libraries.
root
$ld->root( '/mnt' );
Set the root directory to search in.
SEE ALSO
AUTHOR
Philip Gwyn, <gwyn -AT- cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2013-2023 by Philip Gwyn
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.