Back to index

glibc  2.9
restest1.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <error.h>
00003 #include <mcheck.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 
00007 int
00008 main (void)
00009 {
00010   void *h1;
00011   int (*fp1) (int);
00012   void *h2;
00013   int (*fp2) (int);
00014   int res1;
00015   int res2;
00016 
00017   mtrace ();
00018 
00019   h1 = dlopen ("testobj1.so", RTLD_LAZY);
00020   if (h1 == NULL)
00021     error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1.so",
00022           dlerror ());
00023 
00024   h2 = dlopen ("testobj1_1.so", RTLD_LAZY);
00025   if (h1 == NULL)
00026     error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1_1.so",
00027           dlerror ());
00028 
00029   fp1 = dlsym (h1, "obj1func1");
00030   if (fp1 == NULL)
00031     error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
00032           "testobj1.so", dlerror ());
00033 
00034   fp2 = dlsym (h2, "obj1func1");
00035   if (fp2 == NULL)
00036     error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
00037           "testobj1_1.so", dlerror ());
00038 
00039   res1 = fp1 (10);
00040   res2 = fp2 (10);
00041   printf ("fp1(10) = %d\nfp2(10) = %d\n", res1, res2);
00042 
00043   if (dlclose (h1) != 0)
00044     error (EXIT_FAILURE, 0, "cannot close testobj1.so: %s\n", dlerror ());
00045   if (dlclose (h2) != 0)
00046     error (EXIT_FAILURE, 0, "cannot close testobj1_1.so: %s\n", dlerror ());
00047 
00048   return res1 != 42 || res2 != 72;
00049 }
00050 
00051 
00052 extern int foo (int a);
00053 int
00054 foo (int a)
00055 {
00056   return a + 10;
00057 }