#dlopen #dll #so #dylib #shared


The easiest, simplest and safest way to load dynamic (shared object) libraries from Rust!

5 releases (3 breaking)

0.4.0 Jul 14, 2020
0.3.1 Mar 7, 2019
0.3.0 Feb 24, 2019
0.2.0 Jun 26, 2018
0.1.0 Jun 3, 2018

#50 in Windows APIs

Download history 181/week @ 2023-08-13 93/week @ 2023-08-20 87/week @ 2023-08-27 128/week @ 2023-09-03 110/week @ 2023-09-10 106/week @ 2023-09-17 85/week @ 2023-09-24 102/week @ 2023-10-01 95/week @ 2023-10-08 117/week @ 2023-10-15 127/week @ 2023-10-22 134/week @ 2023-10-29 114/week @ 2023-11-05 119/week @ 2023-11-12 121/week @ 2023-11-19 131/week @ 2023-11-26

506 downloads per month
Used in 12 crates (6 directly)

Apache-2.0 OR Zlib

201 lines


The easiest, simplest and safest way to load dynamic (shared object) libraries from Rust!

Build Status Docs crates.io

  • Macro to create a structure that dynamically loads a C API
  • Works on Linux (and probably other unix) and Windows

Roadmap to 1.0 (Future Features)

  • Make it easier to load parts of API at any time (modular loading from same .so file).
  • Support some other obscure OS's.
  • Different loading macro for Rust ABI / other ABIS (possible ABI parameter to the macro?)
  • Make sure it's perfect.

Table of Contents

Getting Started

Add the following to your Cargo.toml.

dl_api = "0.4"


The code inside of the curly braces for link!() matches exactly with code inside of the curly braces for extern "C". This makes it easy for you to turn your extern "C"s into link!()s.

// Shared object: either "libmylibrary.so.1", "mylibrary-1.dll" or "libMyLibrary.dylib"
dl_api::link!(MyApi, "libmylibrary.so.1", {
    fn cFunction(param_name: ParamType) -> ReturnType;

fn main() {
    let api = MyApi::new().unwrap(); // unwrap the `Result`.

    let rtn: ReturnType = unsafe {


API documentation can be found on docs.rs.


There are no optional features.


You can use the changelog to facilitate upgrading this crate as a dependency.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Contributors are always welcome (thank you for being interested!), whether it be a bug report, bug fix, feature request, feature implementation or whatever. Don't be shy about getting involved. I always make time to fix bugs, so usually a patched version of the library will be out a few days after a report. Features requests will not complete as fast. If you have any questions, design critques, or want me to find you something to work on based on your skill level, you can email me at jeronlau@plopgrizzly.com. Otherwise, here's a link to the issues on GitHub. Before contributing, check out the contribution guidelines, and, as always, make sure to follow the code of conduct.