Automatic library init
I am updating a whole set of libraries at work, one of the complaints I am dealing with is the need to initialize the library.
Back in the day (Borland days), there used to be a pragma directive that could be used to automatically call a function with-in the library on startup. I know something like this must exist in gcc but I can't find it.
Does anyone have info?
Quoted 4 lines
Back in the day (Borland days), there used to be a pragma directive that could be used to automatically call a function with-in the library on startup. I know something like this must exist in gcc but I can't find it.
I think the approved method is to use constructor functions:
void cons_func(void) __attribute__((constructor));
void cons_func(void)
{
/* Do initialisation stuff here */
}Note that it isn't hugely well defined what order constructor functions get called in, so be careful when calling other libraries.
Steven.