I meant to post this link a while ago, but here it is anyway:
TP40002013-SW17
So, in a dylib, you can have code execute when the dylib is loaded and execute code when the dylib is being unloaded:
__attribute__((constructor))
static void initializer1() {
printf("[%s] [%s]\n", __FILE__, __FUNCTION__);
}
__attribute__((constructor))
static void initializer2() {
printf("[%s] [%s]\n", __FILE__, __FUNCTION__);
}
__attribute__((destructor))
static void finalizer1() {
printf("[%s] [%s]\n", __FILE__, __FUNCTION__);
}
__attribute__((destructor))
static void finalizer2() {
printf("[%s] [%s]\n", __FILE__, __FUNCTION__);
}