#if SHARED /* Innocent shlib */ #include #include struct object; struct object_dtor_helper; static object& object_generator(); struct object { ~object() { printf("dtor\n"); } }; struct object_dtor_helper { ~object_dtor_helper() { static object obj; } }; static object_dtor_helper objh; #else /* Main program */ #include #include #include int main(int argc, char *argv[]) { void *hdl; hdl = dlopen("./libatexit.so", RTLD_LAZY); assert(hdl != NULL); dlclose(hdl); printf("closed\n"); return (0); } #endif