Home | History | Annotate | Download | only in dlopen
      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <dlfcn.h>
      4 
      5 int main(int argc, char **argv) {
      6     void *handle;
      7     double (*cosine)(double);
      8     char *error;
      9 
     10     handle = dlopen("libm.so.6", RTLD_LAZY);
     11     if (!handle) {
     12         fputs (dlerror(), stderr);
     13         exit(1);
     14     }
     15 
     16     cosine = dlsym(handle, "cos");
     17     if ((error = dlerror()) != NULL)  {
     18         fputs(error, stderr);
     19         exit(1);
     20     }
     21 
     22     printf ("%f\n", (*cosine)(2.0));
     23     dlclose(handle);
     24 }
     25