Linking C & extern(C) on OS X: duplicate symbols not flagged

"Luís "Luís
Thu Aug 29 15:04:49 PDT 2013


On Linux, the following gives out a "multiple definition" error, 
as expected:

     c/test.c:
     void dotest(void) { printf("C\n"); }

     d/test.d:
     extern(C) void dotest() { writeln("D"); }

On OS X no error is flagged, and the C function is always called, 
irrespective of which order I specify the .o files to link. Yet, 
compiling and linking two .c files with a duplication symbol does 
give an error on the linking phase, as expected. So why the 
discrepancy? I'm guessing the cause is the section where the 
symbols appear:

On Ubuntu:

     $ nm d/test.o | grep dotest; echo "--"; nm c/test.o | grep 
dotest
     0000000000000000 T dotest
     --
     0000000000000000 T dotest

On OS X:

     $ nm d/test.o | grep dotest; echo "--"; nm c/test.o | grep 
dotest
     0000000000001490 S _dotest   <-- not in text section, as in 
Linux
     --
     0000000000000000 T _dotest
     0000000000000060 S _dotest.eh

As you might imagine, this situation can be highly disruptive 
(I'm progressively converting a C application to D). Do you know 
why the functions appear in the S section on OS X? Do you know of 
any workaround, to assure that duplicate symbols are correctly 
flagged?


More information about the Digitalmars-d mailing list