1 #include <dlfcn.h>
2 #include <error.h>
3 #include <mcheck.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 int
main(void)8 main (void)
9 {
10 void *h1;
11 int (*fp1) (int);
12 void *h2;
13 int (*fp2) (int);
14 int res1;
15 int res2;
16
17 mtrace ();
18
19 h1 = dlopen ("testobj1.so", RTLD_LAZY);
20 if (h1 == NULL)
21 error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1.so",
22 dlerror ());
23
24 h2 = dlopen ("testobj1_1.so", RTLD_LAZY);
25 if (h1 == NULL)
26 error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1_1.so",
27 dlerror ());
28
29 fp1 = dlsym (h1, "obj1func1");
30 if (fp1 == NULL)
31 error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
32 "testobj1.so", dlerror ());
33
34 fp2 = dlsym (h2, "obj1func1");
35 if (fp2 == NULL)
36 error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
37 "testobj1_1.so", dlerror ());
38
39 res1 = fp1 (10);
40 res2 = fp2 (10);
41 printf ("fp1(10) = %d\nfp2(10) = %d\n", res1, res2);
42
43 if (dlclose (h1) != 0)
44 error (EXIT_FAILURE, 0, "cannot close testobj1.so: %s\n", dlerror ());
45 if (dlclose (h2) != 0)
46 error (EXIT_FAILURE, 0, "cannot close testobj1_1.so: %s\n", dlerror ());
47
48 return res1 != 42 || res2 != 72;
49 }
50
51
52 extern int foo (int a);
53 int
foo(int a)54 foo (int a)
55 {
56 return a + 10;
57 }
58