dlsym
Bindings around the platform's dynamic library loading primitives with greatly improved memory safety. The most important safety guarantee of this library is the prevention of dangling symbols that may occur after a library is unloaded.
use ;
// One-off lookups: the symbol borrows the library.
let libm = unsafe ;
let cos = unsafe ;
assert_eq!;
// Whole APIs: a struct that owns the library and every resolved function.
library!
let m = unsafe ;
assert_eq!;
Compared to libloading
- Symbols don't
Derefto the raw function pointer, so the pointer can't be copied out and outlive the library by accident. ArcSymbolgives'static-friendly symbols withouttransmute.- Only function pointers and raw data pointers can be requested
(
get::<u64>doesn't compile). - The
library!macro and thedlsym-gentool generate structs that resolve a whole API at load time.
dlsym-gen
dlsym-gen turns C headers into dlsym::library! bindings, and eventually
into complete crates with safe wrappers. It's still a work in progress: the
C parser is not implemented yet.
It ships as a binary of this crate behind the codegen feature. Install it
with cargo install dlsym --features codegen, or download a prebuilt binary
(Linux, macOS universal, Windows; x86_64 and aarch64) from the
releases page. The same
engine is available to build.rs scripts as dlsym::codegen.
See ROADMAP.md.
License
MIT