dylib 0.3.2+1
dylib: ^0.3.2+1 copied to clipboard

A set of helpers for resolving names and paths of dynamic libraries.

example/example.dart

import 'dart:ffi' as ffi;

import 'package:dylib/dylib.dart';

void main() {
  libfoo.bar();
}

LibFoo? _libfoo;
LibFoo get libfoo {
  return _libfoo ??= LibFoo(ffi.DynamicLibrary.open(
    resolveDylibPath(
      'foo', // foo.dll, libfoo.so, libfoo.dylib...
      dartDefine: 'LIBFOO_PATH',
      environmentVariable: 'LIBFOO_PATH',
    ),
  ));
}

// e.g. generated by ffigen
class LibFoo {
  final ffi.DynamicLibrary _dylib;
  LibFoo(this._dylib);

  int bar() {
    return (_foo_bar ??=
        _dylib.lookupFunction<_c_foo_bar, _dart_foo_bar>('foo_bar'))();
  }

  _dart_foo_bar? _foo_bar;
}

typedef _c_foo_bar = ffi.Int32 Function();
typedef _dart_foo_bar = int Function();
3
likes
120
pub points
84%
popularity

A set of helpers for resolving names and paths of dynamic libraries.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

meta, path, platform

More

Packages that depend on dylib