Help language development. Donate to The Perl Foundation

Native::FindVersion zef:jjmerelo last updated on 2022-12-19

18ae37949de960699d3f28110d4b5addd90255e8/

Native::FindVersion Test-install distro

Tries to find all available versions of the shared libraries used in native modules.

Installing

Just the usual zef install Native::FindVersion.

Running

It exports a single function, latest-version. An example (from the test)

use Native::FindVersion;

constant $lib-name = "gcc_s";
my $version;
BEGIN {
    $version = latest-version($lib-name);
}

sub __addvdi3( int32 $a, int32 $b) returns int32 is native($lib-name, $version )
{*};

say __addvdi3( 3, 3 )

Since the version needs to be known at compile time, it needs to be assigned during the BEGIN phase. You can use either the short form (foo) or the long form (libfoo).

In this case we're using a shared library and function that can be found in most Linux systems, libgcc.

For ease of use, there's a function that returns directly the native argument:

constant @native-arg = latest-version-arg("gcc_s");
sub gcc-mod( int32 $a, int32 $b)
        returns int32
        is native(@native-arg)
        is symbol("__modti3")
{*};

See also

NativeLibs includes NativeLib::Searcher that will help you find a library using the symbols found in it and a range of possible versions.

Caveats

Untested in Windows and MacOS. If they don't append the version number to the extension, it will not work.

License

(c) JJ Merelo, [email protected] 2022

This module will be licensed, by default, under the Artistic 2.0 License (the same as Raku itself).