can't compile a simple class

Jonathan M Davis jmdavisProg at gmx.com
Sat Mar 23 14:09:55 PDT 2013


On Saturday, March 23, 2013 22:04:23 Patrick Tinkham wrote:
> Sorry for the question. I am a n00b to D. I tried to compile the
> following code from Alexandrescu's book:
> 
> import std.stdio;
> class A {
>    int x = 42;
> }
> 
> unittest {
>    auto a1 = new A;
>    assert (a1.x == 42);
>    auto a2 = a1;
>    a2.x = 100;
>    assert (a1.x == 100);
> }
> 
> at the command line:
> 
> /d$ dmd c.d
> /usr/lib/i386-linux-gnu/libphobos2.a(dmain2_473_1a5.o): In
> function `main':
> src/rt/dmain2.d:(.text.main+0x4): undefined reference to `_Dmain'
> /usr/lib/i386-linux-gnu/libphobos2.a(deh2_453_525.o): In function
> `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
> src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x4):
> undefined reference to `_deh_beg'
> src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0xc):
> undefined reference to `_deh_beg'
> src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x12)
> : undefined reference to `_deh_end'
> 
> ...
> 
> plus much more encrypted Klingon.
> 
> Help?

You have to have a main function. Either add one, or use rdmd --main to 
compile (instead of dmd) so that a stub main is added for you. In either case, 
you need -unittest to enable the unit tests.

Also, questions on learning D should go to the D.Learn newsgroup, whereas this 
is the D newsgroup, which is for general discussion on the language itself.

- Jonathan M Davis


More information about the Digitalmars-d mailing list