Advertisement
Guest User

Untitled

a guest
Feb 15th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <dlfcn.h>
  3.  
  4.  
  5. typedef int ( *func_ptr ) ( int x, int y );
  6. typedef void ( *iter_ptr ) ( int n );
  7.  
  8. int main(void)
  9. {
  10. void *lib = dlopen( "/home/lee/Documents/Nim/libtest.so", RTLD_LAZY );
  11. if ( !lib ) {
  12. printf( "Error in lib.\n" );
  13. }
  14. func_ptr add = dlsym( lib, "add" );
  15. if ( !add ) {
  16. printf( "%s\n", dlerror() );
  17. }
  18.  
  19. iter_ptr iter = dlsym( lib, "iterate" );
  20. if ( !iter ) {
  21. printf( "%s\n", dlerror() );
  22. }
  23. iter(1000);
  24.  
  25. int a = add( 30, 30 );
  26. printf( "a: %d\n", a );
  27. dlclose( lib );
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement