www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - linker errors with class

reply Michael P. <baseball.mjp gmail.com> writes:
Content-Type: text/plain

I'm getting an undefined reference error with Derelict and SDL.
I tried to create an SDLImage class, but I got an error when the files try to
link together.
I've attached the two .d files in a rar.
I compiled with "build imagetest".
I have Bud 3.04, and DMD version 1.036.
I have compiled other SDL programs, so everything is set up properly with
Derelict.

-Michael P.
Oct 25 2008
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to Michael P.,

 I'm getting an undefined reference error with Derelict and SDL.
 I tried to create an SDLImage class, but I got an error when the files
 try to link together.
 I've attached the two .d files in a rar.
 I compiled with "build imagetest".
 I have Bud 3.04, and DMD version 1.036.
 I have compiled other SDL programs, so everything is set up properly
 with Derelict.
 -Michael P.
 

what are the error messages? (copy/pates)
Oct 25 2008
parent reply Michael P. <baseball.mjp gmail.com> writes:
BCS Wrote:

 Reply to Michael P.,
 
 I'm getting an undefined reference error with Derelict and SDL.
 I tried to create an SDLImage class, but I got an error when the files
 try to link together.
 I've attached the two .d files in a rar.
 I compiled with "build imagetest".
 I have Bud 3.04, and DMD version 1.036.
 I have compiled other SDL programs, so everything is set up properly
 with Derelict.
 -Michael P.
 

what are the error messages? (copy/pates)

C:\Documents and Settings\Default\My Documents\DProjects\Derelict\ build imagetest OPTLINK (R) for Win32 Release 8.00.1 Copyright (C) Digital Mars 1989-2004 All rights reserved. SDLImages.obj(SDLImages) Error 42: Symbol Undefined _D9SDLImages11SDL_Imagess5_dtorMFZv
Oct 25 2008
parent reply Mike Parker <aldacron gmail.com> writes:
Michael P. wrote:
 BCS Wrote:
 
 Reply to Michael P.,

 I'm getting an undefined reference error with Derelict and SDL.
 I tried to create an SDLImage class, but I got an error when the files
 try to link together.
 I've attached the two .d files in a rar.
 I compiled with "build imagetest".
 I have Bud 3.04, and DMD version 1.036.
 I have compiled other SDL programs, so everything is set up properly
 with Derelict.
 -Michael P.


C:\Documents and Settings\Default\My Documents\DProjects\Derelict\ build imagetest OPTLINK (R) for Win32 Release 8.00.1 Copyright (C) Digital Mars 1989-2004 All rights reserved. SDLImages.obj(SDLImages) Error 42: Symbol Undefined _D9SDLImages11SDL_Imagess5_dtorMFZv

The linker is expecting to find a destructor for your SDLImagess class in the object file, but it's not there. Your problem is on line 44 of SDLImages.d: //Destructor ~this(); Your destructor is declared, but not implemented -- hence the error. If you've got nothing to do in the destructor, either implement an empty one: ~this() {} Or take it out entirely, in which case the compiler will generate a default destructor for you. IMO, this should really be a compiler error. I'm surprised it isn't.
Oct 26 2008
next sibling parent Michael P. <baseball.mjp gmail.com> writes:
Mike Parker Wrote:

 Michael P. wrote:
 BCS Wrote:
 
 Reply to Michael P.,

 I'm getting an undefined reference error with Derelict and SDL.
 I tried to create an SDLImage class, but I got an error when the files
 try to link together.
 I've attached the two .d files in a rar.
 I compiled with "build imagetest".
 I have Bud 3.04, and DMD version 1.036.
 I have compiled other SDL programs, so everything is set up properly
 with Derelict.
 -Michael P.


C:\Documents and Settings\Default\My Documents\DProjects\Derelict\ build imagetest OPTLINK (R) for Win32 Release 8.00.1 Copyright (C) Digital Mars 1989-2004 All rights reserved. SDLImages.obj(SDLImages) Error 42: Symbol Undefined _D9SDLImages11SDL_Imagess5_dtorMFZv

The linker is expecting to find a destructor for your SDLImagess class in the object file, but it's not there. Your problem is on line 44 of SDLImages.d: //Destructor ~this(); Your destructor is declared, but not implemented -- hence the error. If you've got nothing to do in the destructor, either implement an empty one: ~this() {} Or take it out entirely, in which case the compiler will generate a default destructor for you. IMO, this should really be a compiler error. I'm surprised it isn't.

Thanks, that worked. :D
Oct 26 2008
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
Denis Koroskin wrote:
 On Sun, 26 Oct 2008 10:03:32 +0300, Mike Parker <aldacron gmail.com> wrote:
 
 Michael P. wrote:
 BCS Wrote:

 Reply to Michael P.,

 I'm getting an undefined reference error with Derelict and SDL.
 I tried to create an SDLImage class, but I got an error when the files
 try to link together.
 I've attached the two .d files in a rar.
 I compiled with "build imagetest".
 I have Bud 3.04, and DMD version 1.036.
 I have compiled other SDL programs, so everything is set up properly
 with Derelict.
 -Michael P.


build imagetest OPTLINK (R) for Win32 Release 8.00.1 Copyright (C) Digital Mars 1989-2004 All rights reserved. SDLImages.obj(SDLImages) Error 42: Symbol Undefined _D9SDLImages11SDL_Imagess5_dtorMFZv

The linker is expecting to find a destructor for your SDLImagess class in the object file, but it's not there. Your problem is on line 44 of SDLImages.d: //Destructor ~this(); Your destructor is declared, but not implemented -- hence the error. If you've got nothing to do in the destructor, either implement an empty one: ~this() {} Or take it out entirely, in which case the compiler will generate a default destructor for you. IMO, this should really be a compiler error. I'm surprised it isn't.

No, it shouldn't. You may implement function bodies in other modules and/or languages (in C, for example, just make sure names have proper mangling).

Right, but it just feels wrong to me for constructors & destructors since they are a required part of the class. Either you implement one or you don't, but simply declaring one without an implementation feels like an error to me.
Oct 26 2008
parent torhu <no spam.invalid> writes:
Mike Parker wrote:
...
 Denis Koroskin wrote:
 No, it shouldn't. You may implement function bodies in other modules 
 and/or languages (in C, for example, just make sure names have proper 
 mangling).

Right, but it just feels wrong to me for constructors & destructors since they are a required part of the class. Either you implement one or you don't, but simply declaring one without an implementation feels like an error to me.

Without this feature, .di files wouldn't work. The advantage is that functions without bodies are faster for the compiler to parse, when it it's not going to compile them anyway. You can also use it for hiding implementation, if you don't want your source to be available.
Oct 26 2008
prev sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Sun, 26 Oct 2008 10:03:32 +0300, Mike Parker <aldacron gmail.com> wrote:

 Michael P. wrote:
 BCS Wrote:

 Reply to Michael P.,

 I'm getting an undefined reference error with Derelict and SDL.
 I tried to create an SDLImage class, but I got an error when the files
 try to link together.
 I've attached the two .d files in a rar.
 I compiled with "build imagetest".
 I have Bud 3.04, and DMD version 1.036.
 I have compiled other SDL programs, so everything is set up properly
 with Derelict.
 -Michael P.


build imagetest OPTLINK (R) for Win32 Release 8.00.1 Copyright (C) Digital Mars 1989-2004 All rights reserved. SDLImages.obj(SDLImages) Error 42: Symbol Undefined _D9SDLImages11SDL_Imagess5_dtorMFZv

The linker is expecting to find a destructor for your SDLImagess class in the object file, but it's not there. Your problem is on line 44 of SDLImages.d: //Destructor ~this(); Your destructor is declared, but not implemented -- hence the error. If you've got nothing to do in the destructor, either implement an empty one: ~this() {} Or take it out entirely, in which case the compiler will generate a default destructor for you. IMO, this should really be a compiler error. I'm surprised it isn't.

No, it shouldn't. You may implement function bodies in other modules and/or languages (in C, for example, just make sure names have proper mangling).
Oct 26 2008