void
__attribute ((constructor))
init_function (void)
{
printf("hello world\n");
}
void
__attribute ((destructor))
fini_function (void)
{
printf("bye !!! \n");
}
int foo(int a)
{
return a + 1;
}
Compile the above code as a dynamicl library ,
and
every time dynamic linker loads the library,
the constructor will be invoked,
and when the program exists,
the destructor will be invoked.
Never use _init and _fini as the constructor and destructor of the library, since they are used by system itself.