#dlopen #load #shared #dylib

libloading

A safer binding to platform’s dynamic library loading utilities

21 releases

Uses old Rust 2015

0.6.4 Oct 10, 2020
0.6.2 May 6, 2020
0.5.2 Jul 7, 2019
0.5.0 Jan 11, 2018
0.2.0 Nov 8, 2015

#12 in Operating systems

Download history 55782/week @ 2020-06-30 62361/week @ 2020-07-07 64261/week @ 2020-07-14 68766/week @ 2020-07-21 74256/week @ 2020-07-28 74596/week @ 2020-08-04 77147/week @ 2020-08-11 81081/week @ 2020-08-18 85168/week @ 2020-08-25 82150/week @ 2020-09-01 85651/week @ 2020-09-08 83512/week @ 2020-09-15 84640/week @ 2020-09-22 89391/week @ 2020-09-29 95045/week @ 2020-10-06 83328/week @ 2020-10-13

342,706 downloads per month
Used in 1,564 crates (117 directly)

ISC license

76KB
904 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) as well as use functions and static variables these libraries contain.

While the library does expose a cross-platform interface to load a library and find stuff inside it, little is done to paper over the platform differences, especially where library loading is involved. The documentation for each function will attempt to document such differences on the best-effort basis.

Less safe, platform specific bindings are also available. See the os::platform module for details.

Usage

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

[dependencies]
libloading = "0.6"

Then inside your project

extern crate libloading as lib;

fn call_dynamic() -> Result<u32, Box<dyn std::error::Error>> {
    let lib = lib::Library::new("/path/to/liblibrary.so")?;
    unsafe {
        let func: lib::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 cause of undefined behaviour and memory safety problems.

Dependencies

~28KB