www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - can't compile a simple class

reply "Patrick Tinkham" <patrick_tinkham yahoo.com> writes:
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?
Mar 23 2013
next sibling parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Saturday, 23 March 2013 at 21:04:25 UTC, 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 need a main function: 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); } void main() { }
Mar 23 2013
parent reply "Patrick Tinkham" <patrick_tinkham yahoo.com> writes:
On Saturday, 23 March 2013 at 21:08:39 UTC, Namespace wrote:
 On Saturday, 23 March 2013 at 21:04:25 UTC, 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 need a main function: 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); } void main() { }
Thank you!!! (I guess I'm just accustomed to stand-alone classes in Java...)
Mar 23 2013
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Saturday, 23 March 2013 at 21:12:25 UTC, Patrick Tinkham wrote:
 On Saturday, 23 March 2013 at 21:08:39 UTC, Namespace wrote:
 On Saturday, 23 March 2013 at 21:04:25 UTC, 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:j

 /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 need a main function: 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); } void main() { }
Thank you!!! (I guess I'm just accustomed to stand-alone classes in Java...)
dmd has a flag - - main that auto generates a blank main function to prevent linker errors.
Mar 23 2013
parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
"John Colvin" <john.loughran.colvin gmail.com> wrote in message 
news:czgwwpslprqslewmsjnq forum.dlang.org...
 dmd has a flag - - main that auto generates a blank main function to 
 prevent linker errors.
I don't think this is in the released version yet.
Mar 23 2013
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Sunday, March 24, 2013 16:59:51 Daniel Murphy wrote:
 "John Colvin" <john.loughran.colvin gmail.com> wrote in message
 news:czgwwpslprqslewmsjnq forum.dlang.org...
 
 dmd has a flag - - main that auto generates a blank main function to
 prevent linker errors.
I don't think this is in the released version yet.
It _has_ been in rdmd for quite some time though. - Jonathan M Davis
Mar 23 2013
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Mar 23 2013
prev sibling parent "MattCoder" <mattcoder hotmail.com> writes:
On Saturday, 23 March 2013 at 21:04:25 UTC, Patrick Tinkham wrote:
 /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'
...
 plus much more encrypted Klingon.

 Help?
Fixed: http://dpaste.1azy.net/282d8d3f
Mar 23 2013