#dll #shared #load #dlopen #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

#490 in Operating systems

Download history 89/week @ 2023-12-04 88/week @ 2023-12-11 137/week @ 2023-12-18 151/week @ 2023-12-25 224/week @ 2024-01-01 181/week @ 2024-01-08 96/week @ 2024-01-15 3/week @ 2024-01-22 47/week @ 2024-01-29 21/week @ 2024-02-05 126/week @ 2024-02-12 272/week @ 2024-02-19 159/week @ 2024-02-26 86/week @ 2024-03-04 88/week @ 2024-03-11 74/week @ 2024-03-18

443 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