typo.d:
void mann() { }
michael@michael-laptop:~/d/projects$ dmd typo.d
/home/michael/dmd/linux/bin/../lib/libphobos.a(dmain2_7a_1a5.o): In function `main':
internal/dmain2.d:(.text.main+0x74): undefined reference to `_Dmain'
internal/dmain2.d:(.text.main+0xc5): undefined reference to `_Dmain'
/home/michael/dmd/linux/bin/../lib/libphobos.a(deh2_171_525.o): In function `_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable':
internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x4): undefined reference to `_deh_beg'
internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0xc): undefined reference to `_deh_beg'
internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x13): undefined reference to `_deh_end'
internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x37): undefined reference to `_deh_end'
collect2: ld returned 1 exit status
--- errorlevel 1
Should this be happening?
Compiling with -c is fine, and produces no output.
Comment #1 by b.helyer — 2011-02-07T02:33:12Z
Yes, that is working as intended. When you compile without '-c' you are telling DMD to build you an executable -- one whose entry point is 'main'; so the linker looks for the function, and can't find it, and tells you so. This behaviour is the same as in C or C++.
Comment #2 by bearophile_hugs — 2011-02-07T03:49:26Z
Yet, I'd like the front-end to catch (and show an error message) this common bug before it reaches the linker, if possible.
Comment #3 by b.helyer — 2011-02-11T19:53:50Z
Agreed, but it's not quite as simple as checking the existence of a 'main' function when compiling without -c. If object files, libraries, or anything of the sort are being used -- all those must be searched for a main function. On Linux, where linking is handled by GCC, this would lead to duplication of code and work -- all for a fairly minor issue.
Another option is to merely issue a warning if we don't see one -- this would lead to spurious warnings, and as DMD has no granularity options when it comes to warnings, is not really an option.
So I think the only viable option is to handle the simple case, where the only thing passed to DMD is source files (as we know Phobos doesn't have a main). Not ideal, but should catch cases where the user is genuinely confused by the linker output.