Back to index

glibc  2.9
reldep7.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 int
00006 main (void)
00007 {
00008   void *h1;
00009   void *h2;
00010   void *mod1_bar, *mod2_bar;
00011 
00012   h1 = dlopen ("reldep7mod1.so", RTLD_GLOBAL | RTLD_LAZY);
00013   if (h1 == NULL)
00014     {
00015       printf ("cannot open reldep7mod1.so: %s\n", dlerror ());
00016       exit (1);
00017     }
00018 
00019   h2 = dlopen ("reldep7mod2.so", RTLD_GLOBAL | RTLD_LAZY);
00020   if (h2 == NULL)
00021     {
00022       printf ("cannot open reldep7mod1.so: %s\n", dlerror ());
00023       exit (1);
00024     }
00025 
00026   mod1_bar = dlsym (h1, "mod1_bar");
00027   if (mod1_bar == NULL)
00028     {
00029       printf ("cannot get address of \"mod1_bar\": %s\n", dlerror ());
00030       exit (1);
00031     }
00032 
00033   mod2_bar = dlsym (h2, "mod2_bar");
00034   if (mod2_bar == NULL)
00035     {
00036       printf ("cannot get address of \"mod2_bar\": %s\n", dlerror ());
00037       exit (1);
00038     }
00039 
00040   printf ("%d\n", ((int (*) (void)) mod1_bar) ());
00041   printf ("%d\n", ((int (*) (void)) mod2_bar) ());
00042 
00043   if (dlclose (h1) != 0)
00044     {
00045       printf ("closing h1 failed: %s\n", dlerror ());
00046       exit (1);
00047     }
00048 
00049   printf ("%d\n", ((int (*) (void)) mod2_bar) ());
00050 
00051   if (dlclose (h2) != 0)
00052     {
00053       printf ("closing h2 failed: %s\n", dlerror ());
00054       exit (1);
00055     }
00056 
00057   return 0;
00058 }