1 | #include <dlfcn.h> |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | |
5 | int |
6 | main (void) |
7 | { |
8 | void *h1; |
9 | void *h2; |
10 | void *mod1_bar, *mod2_bar; |
11 | |
12 | h1 = dlopen (file: "reldep7mod1.so" , RTLD_GLOBAL | RTLD_LAZY); |
13 | if (h1 == NULL) |
14 | { |
15 | printf (format: "cannot open reldep7mod1.so: %s\n" , dlerror ()); |
16 | exit (status: 1); |
17 | } |
18 | |
19 | h2 = dlopen (file: "reldep7mod2.so" , RTLD_GLOBAL | RTLD_LAZY); |
20 | if (h2 == NULL) |
21 | { |
22 | printf (format: "cannot open reldep7mod1.so: %s\n" , dlerror ()); |
23 | exit (status: 1); |
24 | } |
25 | |
26 | mod1_bar = dlsym (handle: h1, name: "mod1_bar" ); |
27 | if (mod1_bar == NULL) |
28 | { |
29 | printf (format: "cannot get address of \"mod1_bar\": %s\n" , dlerror ()); |
30 | exit (status: 1); |
31 | } |
32 | |
33 | mod2_bar = dlsym (handle: h2, name: "mod2_bar" ); |
34 | if (mod2_bar == NULL) |
35 | { |
36 | printf (format: "cannot get address of \"mod2_bar\": %s\n" , dlerror ()); |
37 | exit (status: 1); |
38 | } |
39 | |
40 | printf (format: "%d\n" , ((int (*) (void)) mod1_bar) ()); |
41 | printf (format: "%d\n" , ((int (*) (void)) mod2_bar) ()); |
42 | |
43 | if (dlclose (handle: h1) != 0) |
44 | { |
45 | printf (format: "closing h1 failed: %s\n" , dlerror ()); |
46 | exit (status: 1); |
47 | } |
48 | |
49 | printf (format: "%d\n" , ((int (*) (void)) mod2_bar) ()); |
50 | |
51 | if (dlclose (handle: h2) != 0) |
52 | { |
53 | printf (format: "closing h2 failed: %s\n" , dlerror ()); |
54 | exit (status: 1); |
55 | } |
56 | |
57 | return 0; |
58 | } |
59 | |