
1: #include <dlfcn.h> 2: #include <stdio.h> 3: 4: 5: extern void constr (void) __attribute__ ((__constructor__)); 6: void 7: __attribute__ ((__constructor__)) 8: constr (void) 9: { 10: void *handle; 11: void *m; 12: 13: /* Open the library. */ 14: handle = dlopen (NULL, RTLD_NOW); 15: if (handle == NULL) 16: { 17: puts ("Cannot get handle to own object"); 18: return; 19: } 20: 21: /* Get a symbol. */ 22: m = dlsym (handle, "main"); 23: puts ("called dlsym() to get main"); 24: 25: dlclose (handle); 26: }