Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux equivalent of DllMain

In *nix .so libraries, is there an entry point that's invoked by the system when the library is loaded and unloaded?

On a more practical note: if the .so was written in C++ and it contains global objects with constructors and destructors, and it's loaded from a language that has no notion of construction/destruction, are the global objects properly constructed/destructed?

like image 384
Seva Alekseyev Avatar asked Sep 17 '12 16:09

Seva Alekseyev


1 Answers

You can use the __attribute__((constructor)) and __attribute__((destructor)) to execute code on load and unload of the shared library.

like image 114
doron Avatar answered Sep 23 '22 23:09

doron