www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Simple program fails to link - what am I doing wrong?

reply Mike Hearn <mike plan99.net> writes:
I have a feeling this is a real simple problem. What does _D4test7MyClass1bMFZv
demangle to?

class MyClass {
  int a;
  void b();
}


int main() {
  MyClass c;
  return 0;
}

$ dmd -v -run test.d
parse     test
importall test
import    object	(/home/hearn/d/dmd2/linux/bin/../../src/druntime/import/object.di)
semantic  test
semantic2 test
semantic3 test
code      test
function  main
gcc test.o -o test -m32 -Xlinker -L/home/hearn/d/dmd2/linux/bin/../lib
-lphobos2 -lpthread -lm 
test.o:(.rodata+0x34): undefined reference to `_D4test7MyClass1bMFZv'
collect2: ld returned 1 exit status
--- errorlevel 1
Nov 12 2009
next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Thu, 12 Nov 2009 20:22:56 +0300, Mike Hearn <mike plan99.net> wrote:

 I have a feeling this is a real simple problem. What does  
 _D4test7MyClass1bMFZv demangle to?

 class MyClass {
   int a;
   void b();
 }


 int main() {
   MyClass c;
   return 0;
 }

 $ dmd -v -run test.d
 parse     test
 importall test
 import     
 object	(/home/hearn/d/dmd2/linux/bin/../../src/druntime/import/object.di)
 semantic  test
 semantic2 test
 semantic3 test
 code      test
 function  main
 gcc test.o -o test -m32 -Xlinker -L/home/hearn/d/dmd2/linux/bin/../lib  
 -lphobos2 -lpthread -lm
 test.o:(.rodata+0x34): undefined reference to `_D4test7MyClass1bMFZv'
 collect2: ld returned 1 exit status
 --- errorlevel 1

Function MyClass.b is not implemented (but is referenced, because it is put into a virtual function table).
Nov 12 2009
prev sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Thu, 12 Nov 2009 20:22:56 +0300, Mike Hearn <mike plan99.net> wrote:

 I have a feeling this is a real simple problem. What does  
 _D4test7MyClass1bMFZv demangle to?

 class MyClass {
   int a;
   void b();
 }


 int main() {
   MyClass c;
   return 0;
 }

 $ dmd -v -run test.d
 parse     test
 importall test
 import     
 object	(/home/hearn/d/dmd2/linux/bin/../../src/druntime/import/object.di)
 semantic  test
 semantic2 test
 semantic3 test
 code      test
 function  main
 gcc test.o -o test -m32 -Xlinker -L/home/hearn/d/dmd2/linux/bin/../lib  
 -lphobos2 -lpthread -lm
 test.o:(.rodata+0x34): undefined reference to `_D4test7MyClass1bMFZv'
 collect2: ld returned 1 exit status
 --- errorlevel 1

BTW, questions like this belong to D.learn
Nov 12 2009