Subject: Re: C shared lib question
To: Johnny C. Lam <>
From: Jason R Thorpe <>
List: current-users
Date: 03/08/2000 20:04:44
On Wed, Mar 08, 2000 at 09:59:10PM -0500, Johnny C. Lam wrote:

 > I'm porting the ODBC driver for PostgreSQL to NetBSD, but I'm having
 > the following problem.  The code currently defines two functions _init
 > and _fini to call "constructor" and "destructor" code for the shared
 > object:
 > BOOL _init (void)
 > {
 > 	getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
 > 	return TRUE;
 > }
 > Is there a more portable C construct to ensure that a function is
 > called when a shared library is loaded, much like a global static C++
 > object's constructor?

I think that's pretty much how you do it... ELF provides this functionality.

Tho, in GNU C, you can use attributes, like this:

void	my_contructor(void) __attribute__((__constructor__));
void	my_destructor(void) __attribute__((__destructor__));

        -- Jason R. Thorpe <>