#dlopen #load #shared #dylib

libloading

A safer binding to platform’s dynamic library loading utilities

25 releases

Uses old Rust 2015

0.7.0 Feb 6, 2021
0.6.6 Dec 3, 2020
0.6.5 Oct 23, 2020
0.6.2 May 6, 2020
0.2.0 Nov 8, 2015

#12 in Operating systems

Download history 87522/week @ 2020-11-07 92072/week @ 2020-11-14 88977/week @ 2020-11-21 93755/week @ 2020-11-28 95398/week @ 2020-12-05 89053/week @ 2020-12-12 65928/week @ 2020-12-19 56467/week @ 2020-12-26 95656/week @ 2021-01-02 109802/week @ 2021-01-09 106065/week @ 2021-01-16 112251/week @ 2021-01-23 122815/week @ 2021-01-30 112848/week @ 2021-02-06 115352/week @ 2021-02-13 112992/week @ 2021-02-20

402,442 downloads per month
Used in 1,694 crates (146 directly)

ISC license

86KB
907 lines

libloading

Safer bindings around system dynamic library loading primitives. The most important safety guarantee by this library is prevention of dangling-Symbols that may occur after a Library is unloaded.

Using this library allows loading dynamic libraries (also known as shared libraries) as well as use functions and static variables these libraries contain.

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


lib.rs:

A memory-safer wrapper around system dynamic library loading primitives.

Using this library allows loading dynamic libraries (also known as shared libraries) and use functions & global variables contained within the libraries.

libloading crate exposes a cross-platform interface to load a library and utilize its contents, but little is done to paper over the differences in behaviour between different platforms. The API documentation strives to document such differences on the best-effort basis.

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

Usage

Add a dependency on this library to your Cargo.toml:

[dependencies]
libloading = "0.7"

Then inside your code:

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 it comes from, preventing a common class of issues.

Dependencies