linker errors with class

Mike Parker aldacron at gmail.com
Sun Oct 26 00:03:32 PDT 2008


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.
>>>
>> 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

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.


More information about the Digitalmars-d-learn mailing list