windows下dll有入口函数dllmain,可以在dllmain里做一些操作,如释放全局变量等。
那linux下的so有入口函数吗?没有的话全局变量需要怎么释放??
void attribute ((constructor)) xxx_init(void);
void attribute ((destructor)) xxx_fini(void);
void attribute ((constructor)) xxx_init(void);是在main函数之前调用的,void attribute ((destructor)) xxx_fini(void);是在main函数退出之后调用的。官网上的解释:
Libraries should export initialization and cleanup routines using the gcc attribute((constructor)) and attribute((destructor)) function attributes. See the gcc info pages for information on these. Constructor routines are executed before dlopen returns (or before main() is started if the library is loaded at load time). Destructor routines are executed before dlclose returns (or after exit() or completion of main() if the library is loaded at load time)
1 没有入口函数.
2 全局变量只能自己管理了。自己导出一个释放函数,自己调用就可以了。