#include <dlfcn.h>
#include <stdio.h>

typedef int intfunction(int);

int main() {
  void *handle;
  intfunction *fptr;
  int a;
  
  /* open the needed object */
  handle = dlopen("./dllib.so", RTLD_LAZY);
  if (!handle) {
	printf("Failed to open handle, reason: %s\n",dlerror());
  } 

  /* find the address of function */
  fptr = (intfunction *) dlsym(handle, "a_function");
  /*printf("dlerror is: %s\n",dlerror());*/
 
  /* invoke function, passing value of integer as a parameter */
  a = (*fptr)(1);
  
  printf("Result of call was %d\n",a);

  return(0);
}
