Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. // dylib.rs
  2. #[no_mangle]
  3. pub fn minicall() -> u8 {
  4. 3u8
  5. }
  6.  
  7. // caller.rs
  8. use std::dynamic_lib::DynamicLibrary;
  9.  
  10. fn main() {
  11. let mut v = Vec::new();
  12.  
  13. DynamicLibrary::prepend_search_path(&::std::os::getcwd());
  14.  
  15. match DynamicLibrary::open(Some("./libdylib.so")) {
  16. Err(e) => panic!("ERROR: {}", e),
  17. Ok(lib) => {
  18. println!("Unsafe bloc !");
  19. let func = unsafe {
  20. match lib.symbol::< fn() -> u8 >("minicall") {
  21. Err(e) => { panic!("ERROR: {}", e) },
  22. Ok(f) => { *f },
  23. }
  24. };
  25.  
  26. println!("call func !");
  27. let new_value = func();
  28.  
  29. println!("extend vec !");
  30. v.push(new_value);
  31. }
  32. }
  33.  
  34. println!("v is: {}", v);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement