Subject: Re: C shared lib question
To: None <thorpej@shagadelic.org>
From: Klaus Klein <kleink@ira.uka.de>
List: tech-toolchain
Date: 03/09/2000 22:40:33
Jason R Thorpe <thorpej@shagadelic.org> writes:

> On Thu, Mar 09, 2000 at 01:00:56PM -0500, Johnny C. Lam wrote:
> 
>  > >  > BOOL _init (void)
>  > >  > {
>  > >  > 	getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
>  > >  > 	return TRUE;
>  > >  > }
>  > 
>  > but when I compile on NetBSD/i386-ELF, I get:
>  > 
>  > psqlodbc.o: In function `_init':
>  > psqlodbc.o(.text+0x0): multiple definition of `_init'
>  > /usr/lib/crtbeginS.o(.init+0x0): first defined here
>  > /usr/bin/ld: Warning: size of symbol `_init' changed from 48 to 47 in psqlodbc.o
>  > psqlodbc.o: In function `_fini':
>  > psqlodbc.o(.text+0x30): multiple definition of `_fini'
>  > /usr/lib/crtbeginS.o(.fini+0x0): first defined here
>  > /usr/bin/ld: Warning: size of symbol `_fini' changed from 29 to 10 in psqlodbc.o
>  > collect2: ld returned 1 exit status
>  > 
>  > I guess I'm doing something wrong?  I'll try the constructor attribute, next.
> 
> Well, that is sucky.  The linker is supposed to recognize those and stuff
> them into the .init and .fini sections.
> 
> Maybe they need to have "static" as part of their declarations...

That's one way to address this...

Note that identifiers with external linkage and their names beginning
with an underscore are reserved for implementation purposes, so this
simply boils down to a _legitimate_ namespace clash.  Restricting the
identifier linkage to file scope or, preferably, naming them
appropriately, will settle the issue.