Thread overview
linker errors with class
Oct 25, 2008
Michael P.
Oct 25, 2008
BCS
Oct 25, 2008
Michael P.
Oct 26, 2008
Mike Parker
Oct 26, 2008
Michael P.
Oct 26, 2008
Denis Koroskin
Oct 27, 2008
Mike Parker
Oct 27, 2008
torhu
October 25, 2008
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.


October 25, 2008
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)


October 25, 2008
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
October 26, 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.
October 26, 2008
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.
> >>>
> >> 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.


Thanks, that worked. :D
October 26, 2008
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.
>>>>
>>> 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.

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).
October 27, 2008
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.
>>>>>
>>>> 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.
> 
> 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.
October 27, 2008
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.