Home | History | Annotate | Download | only in tests
      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <dlfcn.h>
      4 #include "dlopen_lib.h"
      5 
      6 int main(int argc, char **argv)
      7 {
      8   const char *lib = argc > 1 ? argv[1] : "./libfoo.so";
      9   void *handle;
     10   void (*function)();
     11   const char *error;
     12 
     13   handle = dlopen(lib, RTLD_NOW);
     14   if (!handle) {
     15     fputs (dlerror(), stderr);
     16     exit(1);
     17   }
     18 
     19   function = dlsym(handle, "foo");
     20   error = dlerror();
     21   if (error)  {
     22     fputs(error, stderr);
     23     exit(1);
     24   }
     25 
     26   (*function)();
     27   dlclose(handle);
     28   return 0;
     29 }
     30