5 releases

Uses old Rust 2015

0.1.4 Jun 9, 2019
0.1.3 Jul 17, 2018
0.1.2 May 9, 2018
0.1.1 Sep 5, 2017
0.1.0 Sep 4, 2017

#13 in #dlopen

Download history 20764/week @ 2024-01-06 18492/week @ 2024-01-13 19062/week @ 2024-01-20 19208/week @ 2024-01-27 20995/week @ 2024-02-03 19621/week @ 2024-02-10 13188/week @ 2024-02-17 15757/week @ 2024-02-24 16102/week @ 2024-03-02 17958/week @ 2024-03-09 20098/week @ 2024-03-16 19710/week @ 2024-03-23 19159/week @ 2024-03-30 20645/week @ 2024-04-06 19637/week @ 2024-04-13 17722/week @ 2024-04-20

81,052 downloads per month
Used in 223 crates (17 directly)

MIT license

278 lines


Travis CI Appveyor CI Crates CI Codedov CI Docs


This library is my effort to make use of dynamic link libraries in Rust simple. Previously existing solutions were either unsafe, provided huge overhead of required writing too much code to achieve simple things. I hope that this library will help you to quickly get what you need and avoid errors.

Quick example

extern crate dlopen;
extern crate dlopen_derive;
use dlopen::wrapper::{Container, WrapperApi};

struct Api<'a> {
    example_rust_fun: fn(arg: i32) -> u32,
    example_c_fun: unsafe extern "C" fn(),
    example_reference: &'a mut i32,

fn main(){
    let mut cont: Container<Api> =
        unsafe { Container::load("libexample.so") }.expect("Could not open library or load symbols");
    *cont.example_reference_mut() = 5;


Main features

  • Supports majority of platforms and is platform independent.
  • Is consistent with Rust error handling mechanism and makes making mistakes much more difficult.
  • Is very lightweight. It mostly uses zero cost wrappers to create safer abstractions over platform API.
  • Is thread safe.
  • Is object-oriented programming friendly.
  • Has a low-level API that provides full flexibility of using libraries.
  • Has two high-level APIs that protect against dangling symbols - each in its own way.
  • High level APIs support automatic loading of symbols into structures. You only need to define a structure that represents an API. The rest happens automatically and requires only minimal amount of code.
  • Automatic loading of symbols helps you to follow the DRY paradigm.

Compare with other libraries

Feature dlopen libloading sharedlib
Basic functionality Yes Yes Yes
Multiplatform Yes Yes Yes
Dangling symbol prevention Yes Yes Yes
Thread safety Yes Potential problem with SetErrorMode() on older Windows platforms No support for SetErrorMode (library may block the application on Windows)
Loading of symbols into structures Yes No No
Overhead Minimal Minimal Some overhead
Low-level, unsafe API Yes Yes Yes
Object-oriented friendly Yes No Yes
Load from the program itself Yes No No
Obtaining address information (dladdr) Yes Unix only No


Please note that while Rust aims at being 100% safe language, it does not yet provide mechanisms that would allow me to create a 100% safe library, so I had to settle on 99%. Also the nature of dynamic link libraries requires casting obtained pointers into types that are defined on the application side. And this cannot be safe. Having said that I still think that this library provides the best approach and greatest safety possible in Rust.



dlopen = "0.1"


Cargo documentation


This code is licensed under MIT license.


GitHub changelog


Special thanks to Simonas Kazlauskas whose libloading became code base for my project.


~46K SLoC