On Linux the following gives out a "multiple definition" error, as expected and desired: 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. The cause seems to be OS X DMD (v.2.063.2) outputting the function to the S section: 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 When using LDC on OS X the linking fails, as expected and desired: duplicate symbol _dotest in: d/test.o c/test.o ld: 1 duplicate symbol for architecture x86_64 The LDC .o sections are the same as the C version: $ nm d/test.o | grep dotest; echo "--"; nm c/test.o | grep dotest 0000000000000000 T _dotest 00000000000000b0 S _dotest.eh -- 0000000000000000 T _dotest 0000000000000060 S _dotest.eh
*** This issue has been marked as a duplicate of issue 15342 ***