#dlopen #load #shared #dylib

libloading

A safer binding to platform’s dynamic library loading utilities

15 unstable releases (3 breaking)

0.5.0 Jan 11, 2018
0.4.3 Dec 7, 2017
0.4.2 Sep 24, 2017
0.4.0 May 2, 2017
0.2.0 Nov 8, 2015

#83 in Operating systems

Download history 14177/week @ 2019-01-24 15924/week @ 2019-01-31 17017/week @ 2019-02-07 17387/week @ 2019-02-14 15673/week @ 2019-02-21 16225/week @ 2019-02-28 17640/week @ 2019-03-07 17490/week @ 2019-03-14 14927/week @ 2019-03-21 15865/week @ 2019-03-28 16885/week @ 2019-04-04 19435/week @ 2019-04-11 17430/week @ 2019-04-18 19197/week @ 2019-04-25 16685/week @ 2019-05-02

19,903 downloads per month
Used in 1,069 crates (59 directly)

ISC license

42KB
626 lines


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 dependency to this library to your Cargo.toml:

[dependencies]
libloading = "0.5"

Then inside your project

extern crate libloading as lib;

fn call_dynamic() -> lib::Result<u32> {
    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

~649KB

  • windows winapi 0.3+winerror+errhandlingapi+libloaderapi
  • build build.rs
  • build cc 1.0