16 /* Open the two objects. */
17 h1
= dlopen ("reldepmod1.so", RTLD_LAZY
| RTLD_GLOBAL
);
20 printf ("cannot open reldepmod1.so: %s\n", dlerror ());
23 h2
= dlopen ("reldepmod4.so", RTLD_LAZY
);
26 printf ("cannot open reldepmod4.so: %s\n", dlerror ());
30 /* Get the address of the variable in reldepmod1.so. */
31 vp
= dlsym (h1
, "some_var");
34 printf ("cannot get address of \"some_var\": %s\n", dlerror ());
40 /* Get the function `call_me' in the second object. This has a
41 dependency which is resolved by a definition in reldepmod1.so. */
42 fp
= dlsym (h2
, "call_me");
45 printf ("cannot get address of \"call_me\": %s\n", dlerror ());
49 /* Call the function. */
52 puts ("function \"call_me\" returned wrong result");
56 /* Now close the first object. If must still be around since we have
57 an implicit dependency. */
58 if (dlclose (h1
) != 0)
60 printf ("closing h1 failed: %s\n", dlerror ());
64 /* Open the first object again. */
65 h1
= dlopen ("reldepmod1.so", RTLD_LAZY
| RTLD_GLOBAL
);
68 printf ("cannot open reldepmod1.so the second time: %s\n", dlerror ());
72 /* Get the variable address again. */
73 vp
= dlsym (h1
, "some_var");
76 printf ("cannot get address of \"some_var\" the second time: %s\n",
81 /* The variable now must have its originial value. */
84 puts ("variable \"some_var\" not reset");
88 /* Close the first object again, we are done. */
89 if (dlclose (h1
) != 0)
91 printf ("closing h1 failed: %s\n", dlerror ());
94 if (dlclose (h2
) != 0)
96 printf ("closing h2 failed: %s\n", dlerror ());