cisen / blog

Time waits for no one.
135 stars 20 forks source link

libloading 安全地加载和卸载动态库 #997

Open cisen opened 4 years ago

cisen commented 4 years ago

https://github.com/nagisa/rust_libloading/

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())
    }
}