Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement