Back to index

glibc  2.9
reldepmod4.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 extern int call_me (void);
00006 
00007 int
00008 call_me (void)
00009 {
00010   void *h;
00011   int (*fp) (void);
00012   int res;
00013 
00014   h = dlopen ("reldepmod1.so", RTLD_LAZY);
00015   if (h == NULL)
00016     {
00017       printf ("cannot open reldepmod1.so in %s: %s\n", __FILE__, dlerror ());
00018       exit (1);
00019     }
00020 
00021   fp = dlsym (h, "foo");
00022   if (fp == NULL)
00023     {
00024       printf ("cannot get address of foo in global scope: %s\n", dlerror ());
00025       exit (1);
00026     }
00027 
00028   res = fp () - 42;
00029 
00030   if (dlclose (h) != 0)
00031     {
00032       printf ("failure when closing h in %s: %s\n", __FILE__, dlerror ());
00033       exit (1);
00034     }
00035 
00036   return res;
00037 }