FFI::CheckLib(3pm) | User Contributed Perl Documentation | FFI::CheckLib(3pm) |
FFI::CheckLib - Check that a library is available for FFI
version 0.23
use FFI::CheckLib; check_lib_or_exit( lib => 'jpeg', symbol => 'jinit_memory_mgr' ); check_lib_or_exit( lib => [ 'iconv', 'jpeg' ] ); # or prompt for path to library and then: print "where to find jpeg library: "; my $path = <STDIN>; check_lib_or_exit( lib => 'jpeg', libpath => $path );
This module checks whether a particular dynamic library is available for FFI to use. It is modeled heavily on Devel::CheckLib, but will find dynamic libraries even when development packages are not installed. It also provides a find_lib function that will return the full path to the found dynamic library, which can be feed directly into FFI::Platypus or another FFI system.
Although intended mainly for FFI modules via FFI::Platypus and similar, this module does not actually use any FFI to do its detection and probing. This module does not have any non-core runtime dependencies. The test suite does depend on Test2::Suite.
All of these take the same named parameters and are exported by default.
my(@libs) = find_lib(%args);
This will return a list of dynamic libraries, or empty list if none were found.
[version 0.05]
If called in scalar context it will return the first library found.
Arguments are key value pairs with these keys:
[version 0.11]
As a special case, if "*" is specified then any libs found will match.
A string or array of system paths to search for instead of letting FFI::CheckLib determine the system path. You can set this to "[]" in order to not search any system paths.
use FFI::CheckLib; use FFI::Platypus; my($lib) = find_lib( lib => 'foo', verify => sub { my($name, $libpath) = @_; my $ffi = FFI::Platypus->new; $ffi->lib($libpath); my $f = $ffi->function('foo_version', [] => 'int'); return $f->call() >= 500; # we accept version 500 or better }, );
Recursively search for libraries in any non-system paths (those provided via "libpath" above).
assert_lib(%args);
This behaves exactly the same as find_lib, except that instead of returning empty list of failure it throws an exception.
check_lib_or_exit(%args);
This behaves exactly the same as assert_lib, except that instead of dying, it warns (with exactly the same error message) and exists. This is intended for use in "Makefile.PL" or "Build.PL"
[version 0.05]
my(@libs) = find_lib_or_exit(%args);
This behaves exactly the same as find_lib, except that if the library is not found, it will call exit with an appropriate diagnostic.
[version 0.06]
my(@libs) = find_lib_or_die(%args);
This behaves exactly the same as find_lib, except that if the library is not found, it will die with an appropriate diagnostic.
my $bool = check_lib(%args);
This behaves exactly the same as find_lib, except that it returns true (1) on finding the appropriate libraries or false (0) otherwise.
[version 0.17]
my $path = where($name);
Return the path to the first library that matches the given name.
Not exported by default.
[version 0.17]
my @paths = where($name);
Return the paths to all the libraries that match the given name.
Not exported by default.
[version 0.17]
my $bool = has_symbols($path, @symbol_names);
Returns true if all of the symbols can be found in the dynamic library located at the given path. Can be useful in conjunction with "verify" with "find_lib" above.
Not exported by default.
[version 0.20]
my $path = FFI::CheckLib::system_path;
Returns the system path as a list reference. On some systems, this is "PATH" on others it might be LD_LIBRARY_PATH on still others it could be something completely different. So although you may add items to this list, you should probably do some careful consideration before you do so.
This function is not exportable, even on request.
Author: Graham Ollis <plicease@cpan.org>
Contributors:
Bakkiaraj Murugesan (bakkiaraj)
Dan Book (grinnz, DBOOK)
Ilya Pavlov (Ilya, ILUX)
Shawn Laffan (SLAFFAN)
This software is copyright (c) 2014-2018 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.
2018-11-25 | perl v5.28.0 |