Menu
Library
finalclass
final class Library
Names the native library that provides a binding's C symbol and adds it to the link line.
'c' (libc) is always linked and adds nothing. Any other name is resolved
through pkg-config --libs <name>, then <name>-config --libs, then a plain
-l<name>. Use it with {@see Symbol} on a free function. A library that
needs other linker flags can be listed in the manifest's extensions[].link
instead; duplicates by -l<name> are removed.
Example
use Ffi\Library;
use Ffi\Symbol;
use Ffi\CType;
#[Library('c'), Symbol('atoi'), CType('int')]
function c_atoi(string $s): int { return 0; }
#[Library('c'), Symbol('strlen'), CType('size_t')]
function c_strlen(string $s): int { return 0; }
#[Library('c'), Symbol('htonl'), CType('uint')]
function c_htonl(#[CType('uint')] int $x): int { return 0; }
echo c_atoi("1234"), "\n";
echo c_atoi("-7abc"), "\n";
echo c_strlen("manticore"), "\n";
echo c_htonl(0xFFFFFFFF), "\n";Output
1234
-7
9
4294967295See also: Symbol
Methods
__construct() | Create the attribute. |
__construct()#source
function __construct(public string $name, public ?string $version = null)
Create the attribute.
Parameters
$namestring- library name, e.g.
'c','ssl' $versionstring|null = null- optional library version