The easiest, simplest and safest way to load dynamic (shared object) libraries from Rust!
The code inside of the curly braces for link!()
matches exactly with code inside of the curly
braces for extern "C"
. This makes it easy for you to turn your extern "C"
s into link!()
s.
```rust
// Shared object: either "libmylibrary.so.1", "mylibrary-1.dll" or "libMyLibrary.dylib"
dlapi::link!(MyApi, "libmylibrary.so.1", {
fn cFunction(paramname: ParamType) -> ReturnType;
});
fn main() {
let api = MyApi::new().unwrap(); // unwrap the Result
.
let rtn: ReturnType = unsafe {
(api.cFunction)(0);
};
} ```