FFI::P...pus::DL(3pm)
β¨ NAME β¨
FFI::Platypus::DL β Slightly non-portable interface to libdl. This is the User Contributed Perl Documentation page for FFI::Platypus::DL(3pm), bestie, and it's giving βsmall but mighty loader wrapperβ energy π¦.
πΈ VERSION πΈ
version 2.11 β yes, that's the version, no cap π
.
π¦ SYNOPSIS π¦
use FFI::Platypus 2.00;
use FFI::Platypus::DL;
my $handle = dlopen("./libfoo.so", RTLD_PLATYPUS_DEFAULT);
my $address = dlsym($handle, "my_function_named_foo");
my $ffi = FFI::Platypus->new( api => 2 );
$ffi->function($address => [] => 'void')->call;
dlclose($handle);
π DESCRIPTION π
Okay so FFI::Platypus::DL gives you an interface to libdl, aka the dynamic loader on UNIX. The underlying interface has literally always been used by FFI::Platypus, but it wasn't a public interface until version 0.52. The name changed with that version when it became a public interface, so bestie, be sure to specify that version if you are going to use it. Periodt π.
It's somewhat non-portable for these reasons:
- GNU extensions β It provides some GNU extensions to platforms such as Linux that support them. π
- Windows β It provides an emulation layer on Windows. The emulation layer only supports
RTLD_PLATYPUS_DEFAULTas a flag. The emulation layer emulates the convention described below of passingundefas the dynamic library name to mean, use the currently running executable. The author says: βI've used it without any problems for years, but Windows is not my main development platform.β π«Ά
π₯ FUNCTIONS π₯
These are the dl-prefixed besties, and they're all doing main character energy π
.
πΈ dlopen πΈ
my $handle = dlopen($filename, $flags);
This opens a dynamic library in the context of the dynamic loader. $filename is the full or relative path to a dynamic library (usually a .so on Linux and some other UNIXen, a .dll on Windows and a .dylib on OS X). $flags are flags that can be used to alter the behavior of the library and the symbols it contains. The return value is an opaque pointer (your $handle) which can be used to look up symbols with dlsym. The handle should be closed with dlclose when you are done with it.
By convention if you pass in undef for the filename, the currently loaded executable will be used instead of a separate dynamic library. This is the easiest and most portable way to find the address of symbols in the standard C library. This convention is baked into most UNIXen, but this capability is emulated in Windows which doesn't come with the capability out of the box.
If there is an error in opening the library then undef will be returned and the diagnostic for the failure can be retrieved with dlerror as described below.
Not all flags are supported on all platforms. You can test if a flag is available using can:
if(FFI::Platypus::DL->can('RTLD_LAZY'))
{
...
}
Typically where flags are not mutually exclusive, they can be or'd together:
my $handle = dlopen("libfoo.so", RTLD_LAZY | RTLD_GLOBAL);
Check your operating system documentation for detailed descriptions of these flags.
RTLD_PLATYPUS_DEFAULTβ This is theFFI::Platypusdefault fordlopen(NOTE: NOT thelibdldefault). This is the only flag supported on Windows. For historical reasons, this is usuallyRTLD_LAZYon Unix and0on Windows. πRTLD_LAZYβ Perform lazy binding. π΄RTLD_NOWβ Resolve all symbols before returning fromdlopen. Error if all symbols cannot resolve. π€RTLD_GLOBALβ Symbols are shared. πRTLD_LOCALβ Symbols are NOT shared. πRTLD_NODELETEβ glibc2.2extension. π§©RTLD_NOLOADβ glibc2.2extension. π§©RTLD_DEEPBINDβ glibc2.3.4extension. π§©
π¦ dlsym π¦
my $opaque = dlsym($handle, $symbol);
This looks up the given $symbol in the library pointed to by $handle. If the symbol is found, the address for that symbol is returned as an opaque pointer. This pointer can be passed into the FFI::Platypus function and attach methods instead of a function name.
If the symbol cannot be found then undef will be returned and the diagnostic for the failure can be retrieved with dlerror as described below.
π dlclose π
my $status = dlclose($handle);
On success, dlclose returns 0; on error, it returns a nonzero value, and the diagnostic for the failure can be retrieved with dlerror as described below.
π dlerror π
my $error_string = dlerror;
Returns the human readable diagnostic for the reason for the failure for the most recent dl prefixed function call.
π CAVEATS π
Some flags for dlopen are not portable. This module may not be supported for platforms added to FFI::Platypus in the future. It does work as far as I know on all of the currently supported platforms. Be aware, bestie β portability is not always giving slay. π
π SEE ALSO π
FFI::Platypus β go see also it, obviously π.
π AUTHOR π
Author: Graham Ollis <plicease@cpan.org>
Contributors:
- Bakkiaraj Murugesan (bakkiaraj)
- Dylan Cali (calid)
- pipcet
- Zaki Mughal (zmughal)
- Fitz Elliott (felliott)
- Vickenty Fesunov (vyf)
- Gregor Herrmann (gregoa)
- Shlomi Fish (shlomif)
- Damyan Ivanov
- Ilya Pavlov (Ilya33)
- Petr PΓsaΕ (ppisar)
- Mohammad S Anwar (MANWAR)
- HΓ₯kon HΓ¦gland (hakonhagland, HAKONH)
- Meredith (merrilymeredith, MHOWARD)
- Diab Jerius (DJERIUS)
- Eric Brine (IKEGAMI)
- szTheory
- JosΓ© JoaquΓn Atria (JJATRIA)
- Pete Houston (openstrike, HOUSTON)
- Lukas Mai (MAUKE)
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2015-2022 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
π okay bestie, that's the whole page! π Source/version: perl v5.42.3; date: 2026-08-20; footer manual tag: FFI::P...pus::DL(3pm). Bye bestie, go slay some dynamic loading! π«Άβ¨
π¦ where this page comes from
- ubuntu stonking: libffi-platypus-perl 2.11-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms