#shared #load #dylib #dlopen #api-bindings #behavior

libloading

Bindings around the platform's dynamic library loading primitives with greatly improved memory safety

33 releases

Uses old Rust 2015

0.8.3 Mar 5, 2024
0.8.1 Sep 30, 2023
0.8.0 Apr 11, 2023
0.7.4 Nov 6, 2022
0.2.0 Nov 8, 2015

#1 in #shared

Download history 1187504/week @ 2024-01-05 1075705/week @ 2024-01-12 1156748/week @ 2024-01-19 1109428/week @ 2024-01-26 1136692/week @ 2024-02-02 1179176/week @ 2024-02-09 1107862/week @ 2024-02-16 1277821/week @ 2024-02-23 1228623/week @ 2024-03-01 1174797/week @ 2024-03-08 1194468/week @ 2024-03-15 1203747/week @ 2024-03-22 1250908/week @ 2024-03-29 1181635/week @ 2024-04-05 1188021/week @ 2024-04-12 1083851/week @ 2024-04-19

4,926,319 downloads per month
Used in 6,233 crates (441 directly)

ISC license

93KB
940 lines

Contains (Windows DLL, 4KB) tests/nagisa32.dll, (Windows DLL, 3KB) tests/nagisa64.dll

libloading

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.

Using this library allows the loading of dynamic libraries, also known as shared libraries, as well as the use of the functions and static variables that these libraries may contain.

libloading is available to use under ISC (MIT-like) license.


lib.rs:

Bindings around the platform's dynamic library loading primitives with greatly improved memory safety.

Using this library allows the loading of dynamic libraries, also known as shared libraries, and the use of the functions and static variables they contain.

The libloading crate exposes a cross-platform interface to load a library and make use of its contents, but little is done to hide the differences in behaviour between platforms. The API documentation strives to document such differences as much as possible.

Platform-specific APIs are also available in the os module. These APIs are more flexible, but less safe.

Installation

Add the libloading library to your dependencies in Cargo.toml:

[dependencies]
libloading = "0.8"

Usage

In your code, run the following:

fn call_dynamic() -> Result<u32, Box<dyn std::error::Error>> {
    unsafe {
        let lib = libloading::Library::new("/path/to/liblibrary.so")?;
        let func: libloading::Symbol<unsafe extern fn() -> u32> = lib.get(b"my_func")?;
        Ok(func())
    }
}

The compiler will ensure that the loaded function will not outlive the Library from which it comes, preventing the most common memory-safety issues.

Dependencies

~0–5MB