[R-SIG-Mac] ld: multiple definitions of symbol

Thomas Lumley tlumley at u.washington.edu
Tue Jan 13 09:25:04 CET 2009

On Mon, 12 Jan 2009, Simon Urbanek wrote:

> On Jan 12, 2009, at 7:59 , Hadassa Brunschwig wrote:
>> I obtain errors of the sort:
>> ld: multiple definitions of symbol _ivector
>> nrutil.o definition of _ivector in section (__TEXT,__text)
>> tools.o definition of _ivector in section (__TEXT,__text)
>> I read somewhere that this is due to multiple compilers but I am not
>> sure about that.
> No, this is a bug in your code - it's because you have multiple definitions of 
> the same symbol (ivector). If you want the two symbols to be the same across 
> modules, you must declare it external in one of the two files. If you want 
>them separate, declare both static.

It might be worth pointing out that this is an area where C compilers differ. Many compilers permit multiple definitions: if they are the same, the behaviour is as if all but one are extern and if they are not the same the behaviour is undefined or implementation-defined.  I have read (I don't know if it's true) that this handling of multiple definitions was actually necessary for the early C++ compilers that compiled to C.

There's some discussion in the Rationale to the C standard

Anyway, Simon is right that the Apple gcc demands that there is an extern on all but one declaration, and the Standard allows the compiler to demand this, and a program written this way will work correctly on compilers that have different views, so it's a good way to write.


Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

More information about the R-SIG-Mac mailing list