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

/* cc -o testdl testdl.c -ldl */
/* cc -shared -o fn.so fn.c -lm */

main()
{

   char obj[100],fn[100];
   double x,answer;
   double (*func)(double);
   void *handl,*dlval;


   printf("Name of object file? ");
   scanf("%s",obj);

   printf("%s\n",obj);

   if((handl = dlopen(obj,1)) == NULL){
	   fprintf(stderr,"Error in dynamic load.  Exiting ...\n");
	   fprintf(stderr,"%s",dlerror());
	   exit(1);
	   }

   printf("Name of function? ");
   scanf("%s",fn);
   
   if((dlval = dlsym(handl,fn)) == NULL){
	fprintf(stderr,"Error in accessing function.\n");
	exit(1);
	}

   printf("Value ? ");
   scanf("%lf",&x);

   func = (double(*)(double))dlval;

   answer = (*func)(x);

   printf("The answer is %lf\n",answer);

}


   

  

