(本文未经许可禁止转载)

           

使用外部库libloading的策略

[dependencies]
libloading = "0.8"
fn call_dynamic() -> Result< u32, Box< dyn std::error::Error > > {
    unsafe {
        let lib = libloading::Library::new("/path/to/liblibrary.so")?;
        let func: libloading::Symbol u32> = lib.get(b"my_func")?;
        Ok(func())
    }
}

https://docs.rs/libloading/latest/libloading/

       

(本文未经许可禁止转载)

   

发表回复