123456789_123456789_123456789_123456789_123456789_

Alternate Names

When loading a library with alternate file names:

ffi_lib ['foo', 'foo-1.2']

Linux Packages

When you install libfoo on a Debian or RedHat based Linux system, it will install libfoo.so.1 but will not install libfoo.so. Linux package maintainers will put the libfoo.so file into a development package (libfoo-dev on Debian or libfoo-devel on RedHat). To prevent users from having to install both the library package and the development package:

ffi_lib ['foo', 'libfoo.so.1']

In-memory Libraries

When the library you need to bind against has already been loaded into memory, use FFI::CURRENT_PROCESS:

ffi_lib [FFI::CURRENT_PROCESS, 'c']

Function Visibility

Some libraries are compiled such that they depend on functions existing in the global namespace. This makes things problematic for FFI when attaching the functions. However, you can instruct FFI to load the library and make all symbols visible globally within the process.

ffi_lib_flags :now, :global
ffi_lib 'foo'