Skip to content
php-ffiPublic

Repository files navigation

Library Location Resolver

PHP 8.1+ Latest Stable Version Latest Unstable Version Total Downloads License MIT

FFI::cdef() fails with a cryptic error when a shared library is missing, and the same library is named differently on each operating system (libvulkan.so.1, vulkan-1.dll, libvulkan.1.dylib). This package finds the library before you load it, the way the dynamic linker of the operating system searches it, so you can check that it is installed, pick the name that exists and report a clear error.

Installation

composer require ffi/location

Requires PHP 8.1 or later.

Usage

use FFI\Location\Locator;

$pathname = Locator::resolve('libvulkan.so.1', 'vulkan-1.dll', 'libvulkan.1.dylib')
    ?? throw new RuntimeException('Vulkan is not installed');

$vulkan = FFI::cdef($header, $pathname);

Documentation

The search order on each system, the options and the limitations are described in the documentation.

Releases

Used by

Contributors

Languages