www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Weird Link Error

reply "Daniel" <danaubie gmail.com> writes:
I have searched everywhere and I can't find anything so I decided 
to come here. I have a simple Hello World program in the file 
Test.d, it compiles just fine but when I try this...

[daniel arch D]$ dmd Test.o
/usr/lib/libphobos2.a(dmain2_459_1a5.o): In function 
`_D2rt6dmain24mainUiPPaZi7runMainMFZv':
(.text._D2rt6dmain24mainUiPPaZi7runMainMFZv+0x10): undefined 
reference to `_Dmain'
/usr/lib/libphobos2.a(deh2_43b_525.o): In function 
`_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x4): 
undefined reference to `_deh_beg'
/usr/lib/libphobos2.a(deh2_43b_525.o): In function 
`_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0xc): 
undefined reference to `_deh_beg'
/usr/lib/libphobos2.a(deh2_43b_525.o): In function 
`_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x13): 
undefined reference to `_deh_end'
/usr/lib/libphobos2.a(deh2_43b_525.o): In function 
`_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x36): 
undefined reference to `_deh_end'
/usr/lib/libphobos2.a(thread_18f_1b8.o): In function 
`_D4core6thread6Thread6__ctorMFZC4core6thread6Thread':
(.text._D4core6thread6Thread6__ctorMFZC4core6thread6Thread+0x1d): 
undefined reference to `_tlsend'
/usr/lib/libphobos2.a(thread_18f_1b8.o): In function 
`_D4core6thread6Thread6__ctorMFZC4core6thread6Thread':
(.text._D4core6thread6Thread6__ctorMFZC4core6thread6Thread+0x24): 
undefined reference to `_tlsstart'
/usr/lib/libphobos2.a(thread_19f_6e4.o): In function 
`thread_attachThis':
(.text.thread_attachThis+0xb7): undefined reference to `_tlsstart'
/usr/lib/libphobos2.a(thread_19f_6e4.o): In function 
`thread_attachThis':
(.text.thread_attachThis+0xbc): undefined reference to `_tlsend'
/usr/lib/libphobos2.a(thread_17d_1b8.o): In function 
`_D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread':
(.text._D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread+0x1d): 
undefined reference to `_tlsend'
/usr/lib/libphobos2.a(thread_17d_1b8.o): In function 
`_D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread':
(.text._D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread+0x27): 
undefined reference to `_tlsstart'
/usr/lib/libphobos2.a(thread_17e_1b8.o): In function 
`_D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread':
(.text._D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread+0x1d): 
undefined reference to `_tlsend'
/usr/lib/libphobos2.a(thread_17e_1b8.o): In function 
`_D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread':
(.text._D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread+0x27): 
undefined reference to `_tlsstart'
/usr/lib/libphobos2.a(thread_17a_713.o): In function 
`thread_entryPoint':
(.text.thread_entryPoint+0x64): undefined reference to `_tlsend'
/usr/lib/libphobos2.a(thread_17a_713.o): In function 
`thread_entryPoint':
(.text.thread_entryPoint+0x6a): undefined reference to `_tlsstart'
collect2: error: ld returned 1 exit status
--- errorlevel 1

I would try to solve the problem myself, except that I have no 
clue wtf this means.
Sep 20 2012
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 20 September 2012 at 13:08:19 UTC, Daniel wrote:
  undefined reference to `_Dmain'

Does your program have a main() function?
Sep 20 2012
prev sibling next sibling parent "Daniel" <danaubie gmail.com> writes:
On Thursday, 20 September 2012 at 13:12:41 UTC, Adam D. Ruppe 
wrote:
 On Thursday, 20 September 2012 at 13:08:19 UTC, Daniel wrote:
 undefined reference to `_Dmain'

Does your program have a main() function?

Oh wow I had the main function inside a class, I can't believe the answer was so simple. I feel like an idiot now.
Sep 20 2012
prev sibling next sibling parent Jens Mueller <jens.k.mueller gmx.de> writes:
Daniel wrote:
 I have searched everywhere and I can't find anything so I decided to
 come here. I have a simple Hello World program in the file Test.d,
 it compiles just fine but when I try this...

Can you attach the Test.d? But it looks like you didn't define a main function.
 [daniel arch D]$ dmd Test.o
 /usr/lib/libphobos2.a(dmain2_459_1a5.o): In function
 `_D2rt6dmain24mainUiPPaZi7runMainMFZv':
 (.text._D2rt6dmain24mainUiPPaZi7runMainMFZv+0x10): undefined
 reference to `_Dmain'
 /usr/lib/libphobos2.a(deh2_43b_525.o): In function
 `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
 (.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x4):
 undefined reference to `_deh_beg'
 /usr/lib/libphobos2.a(deh2_43b_525.o): In function
 `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
 (.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0xc):
 undefined reference to `_deh_beg'
 /usr/lib/libphobos2.a(deh2_43b_525.o): In function
 `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
 (.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x13):
 undefined reference to `_deh_end'
 /usr/lib/libphobos2.a(deh2_43b_525.o): In function
 `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
 (.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x36):
 undefined reference to `_deh_end'
 /usr/lib/libphobos2.a(thread_18f_1b8.o): In function
 `_D4core6thread6Thread6__ctorMFZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFZC4core6thread6Thread+0x1d):
 undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_18f_1b8.o): In function
 `_D4core6thread6Thread6__ctorMFZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFZC4core6thread6Thread+0x24):
 undefined reference to `_tlsstart'
 /usr/lib/libphobos2.a(thread_19f_6e4.o): In function
 `thread_attachThis':
 (.text.thread_attachThis+0xb7): undefined reference to `_tlsstart'
 /usr/lib/libphobos2.a(thread_19f_6e4.o): In function
 `thread_attachThis':
 (.text.thread_attachThis+0xbc): undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_17d_1b8.o): In function
 `_D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread+0x1d):
 undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_17d_1b8.o): In function
 `_D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread+0x27):
 undefined reference to `_tlsstart'
 /usr/lib/libphobos2.a(thread_17e_1b8.o): In function
 `_D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread+0x1d):
 undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_17e_1b8.o): In function
 `_D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread+0x27):
 undefined reference to `_tlsstart'
 /usr/lib/libphobos2.a(thread_17a_713.o): In function
 `thread_entryPoint':
 (.text.thread_entryPoint+0x64): undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_17a_713.o): In function
 `thread_entryPoint':
 (.text.thread_entryPoint+0x6a): undefined reference to `_tlsstart'
 collect2: error: ld returned 1 exit status
 --- errorlevel 1
 
 I would try to solve the problem myself, except that I have no clue
 wtf this means.

These are linker errors. Just read the first two line:
 /usr/lib/libphobos2.a(dmain2_459_1a5.o): In function
 `_D2rt6dmain24mainUiPPaZi7runMainMFZv':
 (.text._D2rt6dmain24mainUiPPaZi7runMainMFZv+0x10): undefined
 reference to `_Dmain'

The linker looks for a D main function since it is referenced in the function with mangled name _D2rt6dmain24mainUiPPaZi7runMainMFZv. But it cannot find it (i.e. the reference is undefined) you'll get this error and subsequent errors. Jens
Sep 20 2012
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 20 September 2012 at 13:19:08 UTC, Daniel wrote:
 Oh wow I had the main function inside a class, I can't believe 
 the answer was so simple. I feel like an idiot now.

The linker errors are really hard to read if you haven't seen them before (and sometimes even then)...
Sep 20 2012
prev sibling next sibling parent "Daniel" <danaubie gmail.com> writes:
On Thursday, 20 September 2012 at 13:38:03 UTC, Adam D. Ruppe 
wrote:
 On Thursday, 20 September 2012 at 13:19:08 UTC, Daniel wrote:
 Oh wow I had the main function inside a class, I can't believe 
 the answer was so simple. I feel like an idiot now.

The linker errors are really hard to read if you haven't seen them before (and sometimes even then)...

Yeah I'm new to D if you couldn't tell. I figured it must have been something I did wrong when I installed dmd, but I guess it was just a dumb mistake.
Sep 20 2012
prev sibling parent "freeman" <freeman no-one.com> writes:
I started seeing these same errors after installing 2.6.  Perhaps
it is a linker problem tied to some conf file (in debian or dmd)?
The crude solution that works for me is to delete / re-establish
soft-linked libraries.

On Thursday, 20 September 2012 at 13:08:19 UTC, Daniel wrote:
 I have searched everywhere and I can't find anything so I 
 decided to come here. I have a simple Hello World program in 
 the file Test.d, it compiles just fine but when I try this...

 [daniel arch D]$ dmd Test.o
 /usr/lib/libphobos2.a(dmain2_459_1a5.o): In function 
 `_D2rt6dmain24mainUiPPaZi7runMainMFZv':
 (.text._D2rt6dmain24mainUiPPaZi7runMainMFZv+0x10): undefined 
 reference to `_Dmain'
 /usr/lib/libphobos2.a(deh2_43b_525.o): In function 
 `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
 (.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x4): 
 undefined reference to `_deh_beg'
 /usr/lib/libphobos2.a(deh2_43b_525.o): In function 
 `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
 (.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0xc): 
 undefined reference to `_deh_beg'
 /usr/lib/libphobos2.a(deh2_43b_525.o): In function 
 `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
 (.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x13): 
 undefined reference to `_deh_end'
 /usr/lib/libphobos2.a(deh2_43b_525.o): In function 
 `_D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable':
 (.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh29FuncTable+0x36): 
 undefined reference to `_deh_end'
 /usr/lib/libphobos2.a(thread_18f_1b8.o): In function 
 `_D4core6thread6Thread6__ctorMFZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFZC4core6thread6Thread+0x1d): 
 undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_18f_1b8.o): In function 
 `_D4core6thread6Thread6__ctorMFZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFZC4core6thread6Thread+0x24): 
 undefined reference to `_tlsstart'
 /usr/lib/libphobos2.a(thread_19f_6e4.o): In function 
 `thread_attachThis':
 (.text.thread_attachThis+0xb7): undefined reference to 
 `_tlsstart'
 /usr/lib/libphobos2.a(thread_19f_6e4.o): In function 
 `thread_attachThis':
 (.text.thread_attachThis+0xbc): undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_17d_1b8.o): In function 
 `_D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread+0x1d): 
 undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_17d_1b8.o): In function 
 `_D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFPFZvkZC4core6thread6Thread+0x27): 
 undefined reference to `_tlsstart'
 /usr/lib/libphobos2.a(thread_17e_1b8.o): In function 
 `_D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread+0x1d): 
 undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_17e_1b8.o): In function 
 `_D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread':
 (.text._D4core6thread6Thread6__ctorMFDFZvkZC4core6thread6Thread+0x27): 
 undefined reference to `_tlsstart'
 /usr/lib/libphobos2.a(thread_17a_713.o): In function 
 `thread_entryPoint':
 (.text.thread_entryPoint+0x64): undefined reference to `_tlsend'
 /usr/lib/libphobos2.a(thread_17a_713.o): In function 
 `thread_entryPoint':
 (.text.thread_entryPoint+0x6a): undefined reference to 
 `_tlsstart'
 collect2: error: ld returned 1 exit status
 --- errorlevel 1

 I would try to solve the problem myself, except that I have no 
 clue wtf this means.

Sep 20 2012