Crate libloading[][src]

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.

Modules

changelog

The change log.

os

Unsafe but flexible platform specific bindings to dynamic library loading facilities.

Structs

Library

A loaded dynamic library.

Symbol

Symbol from a library.

Enums

Error

Errors.

Functions

library_filename

Converts a library name to a filename generally appropriate for use on the system.