#dll #dlopen #load #shared #so

libloader

A easy-to-use dll loader for rust that based on libloading

5 releases

0.1.4 Sep 12, 2022
0.1.3 Sep 12, 2022
0.1.2 Sep 12, 2022
0.1.1 Sep 12, 2022
0.1.0 Sep 12, 2022

#622 in Operating systems

42 downloads per month
Used in 2 crates

Custom license

445KB

Contains (Mach-o library, 440KB) libstd.dylib

libloader

libloader is a easy-to-use DLL loader for rust that based on libloading

It is very easy to dynamically call a function from dynamic link library (DLL files for Windows, so files for Unix/Linux dylib for macOS )

Use this function to get the function from DLL

get_libfn!(
    "path.dll",
    "func_name",
    name_to_call,
    return_type, // ifreturn type is none, use "()" instead
    param1_name: param1_type
    param2_name: param2_type
    param3_name: param3_type
    ...
);

For example, We have these functions from libstd.dylib

// lib.rs (compiled into libstd.dylib)
#[no_mangle]
pub fn println(str: &str) {
    println!("{}", str);
}

#[no_mangle]
pub fn add(a: usize, b: usize) -> usize {
    a + b
}

#[no_mangle]
pub fn print_hello() {
    println!("Hello");
}

We can call it with:

// main.rs
use libloader::libloading
fn main() {
    get_libfn!("libstd.dylib", "println", my_println, (), str: &str);
    my_println("Hello World");

    get_libfn!("libstd.dylib", "add", my_add, usize, a: usize, b: usize);
    println!("10 + 20 = {}", my_add(10, 20));

    get_libfn!("libstd.dylib", "print_hello", my_print_hello, ());
    my_print_hello();
}

The output is:

Hello World
10 + 20 = 30
hello

Dependencies