gcc linkage problem with C & D

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Jul 26 23:39:06 PDT 2007


Charles D Hixson wrote:
[snip]
> /usr/local/dmd/lib/libphobos.a(dmain2.o): In function `main':
> internal/dmain2.d:(.gnu.linkonce.tmain+0x74): undefined reference to 
> `_Dmain'
> internal/dmain2.d:(.gnu.linkonce.tmain+0xc5): undefined reference to 
> `_Dmain'
> /usr/local/dmd/lib/libphobos.a(deh2.o): In function 
> `_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable':
> internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x9): 
> undefined reference to `_deh_beg'
> internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0xe): 
> undefined reference to `_deh_beg'
> internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x14): 
> undefined reference to `_deh_end'
> internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x37): 
> undefined reference to `_deh_end'
> collect2: ld returned 1 exit status
> make: *** [test0] Error 1
> 
> 
> Which totally boggles me.
[snip makefile]
> 
> (minus some wrapping that happened in posting).  The other files are 
> unchanged:  test0c.c is a "hello, world" function, and test0d.d is a 
> main routine that just calls the function.

Are you sure? The error messages would seem to indicate that there's no 
_Dmain, which is the mangled version of a D main() and which should be 
present if your main() is in test0d.d. Perhaps you could post your 
source files?

About the different *main functions:
The D runtime declares its own C main() which calls the D main() after 
initializing the runtime. And when DMD sees the DMD main routine it 
emits some extra symbols (_deh*) it uses to locate D exception handling 
information. Since both seem to be missing I'd say you either didn't 
define a main function in your D code or you mistakenly declared it 
extern(C) or something...


More information about the Digitalmars-d-learn mailing list