我目前正在玩DynamicLibrary
。手動調用防鏽動態庫
我的動態庫(編譯rustc --crate-type dylib dylib.rs
)代碼:
// dylib.rs
#[no_mangle]
pub fn minicall() -> u8 {
3u8
}
和代碼來調用它:
// caller.rs
use std::dynamic_lib::DynamicLibrary;
fn main() {
let mut v = Vec::new();
DynamicLibrary::prepend_search_path(&::std::os::getcwd());
match DynamicLibrary::open(Some("./libdylib.so")) {
Err(e) => panic!("ERROR: {}", e),
Ok(lib) => {
println!("Unsafe bloc !");
let func = unsafe {
match lib.symbol::< fn() -> u8 >("minicall") {
Err(e) => { panic!("ERROR: {}", e) },
Ok(f) => { *f },
}
};
println!("call func !");
let new_value = func();
println!("extend vec !");
v.push(new_value);
}
}
println!("v is: {}", v);
}
我有這樣的輸出:
~> ./caller
Unsafe bloc !
call func !
Illegal instruction
而且在這裏我很迷茫。我究竟做錯了什麼 ?
哦,我明白了,謝謝。文檔根本不清楚。 – Levans 2014-11-02 14:45:54
這是非常慈善的;目前沒有真正的文檔......我甚至在source-dive^_ ^的時候看到了'#![allow(missing_docs)]'。 – Shepmaster 2014-11-02 16:40:23