Thanks to visit codestin.com
Credit goes to lib.rs

#dlopen #dylib #api-bindings

no-std libloading

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

40 releases

0.9.0 Nov 5, 2025
0.8.8 May 26, 2025
0.8.6 Nov 29, 2024
0.8.5 Jul 20, 2024
0.2.0 Nov 8, 2015

#5 in Operating systems

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

10,891,086 downloads per month
Used in 10,439 crates (776 directly)

ISC license

115KB
1.5K SLoC

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

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 "C" 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.


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.

Dependencies