dylib 0.3.3 dylib: ^0.3.3 copied to clipboard
A set of helpers for resolving names and paths of dynamic libraries.
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 (_fooBar ??=
_dylib.lookupFunction<_CFooBar, _DartFooBar>('foo_bar'))();
}
_DartFooBar? _fooBar;
}
typedef _CFooBar = ffi.Int32 Function();
typedef _DartFooBar = int Function();