Thread overview
linker: undefined symbol when an interface is derived from.
Feb 26, 2007
Neal Alexander
Feb 27, 2007
Neal Alexander
Feb 27, 2007
Neal Alexander
February 26, 2007
The IDirect3D8 interface works fine if its used opaquely with the various directx routines; but when the interface is used to make a class that implements it, or in this case wraps it, the linker cant find the IDirect3D8 interface symbol.

Scope issues or compiler bug?


> dmd file2.d file1.d uuid.lib d3d8.lib

file2.obj(dx8_wrapper)
 Error 42: Symbol Undefined _D4d3d810IDirect3D811__InterfaceZ


---------------------------------------------------------------------
d3d8.d
---------------------------------------------------------------------
// ... snip ...

extern (Windows):
interface IDirect3D8 : public IUnknown
{
    /*** IUnknown methods ***/
    //HRESULT QueryInterface(IID*, void**);
    //ULONG AddRef();
    //ULONG Release();

    // ... snip ...

    HRESULT CreateDevice(UINT,D3DDEVTYPE,HWND,DWORD,
                         D3DPRESENT_PARAMETERS*,IDirect3DDevice8*);
}

// ...
---------------------------------------------------------------------
file1.d
---------------------------------------------------------------------
import d3d8;


extern (Windows):
class dx8_wrapper : ComObject, public IDirect3D8
{
    // ... snip ...

    HRESULT CreateDevice(
        UINT adapter,
        D3DDEVTYPE type,
        HWND window,
        DWORD flags,
        D3DPRESENT_PARAMETERS * pp,
        IDirect3DDevice8      * result)
    {
        HRESULT ret;

	ret = d3d.CreateDevice(adapter, type,
                               window, flags, pp, &device);
        *result = device;

        return ret;
    }

    this(IDirect3D8 base){ d3d = base; }

    IDirect3D8       d3d;
    IDirect3DDevice8 device;
}




February 27, 2007
"Neal Alexander" <wqeqweuqy@hotmail.com> wrote in message news:erv3kf$2ukm$1@digitalmars.com...
> The IDirect3D8 interface works fine if its used opaquely with the various directx routines; but when the interface is used to make a class that implements it, or in this case wraps it, the linker cant find the IDirect3D8 interface symbol.
>
> Scope issues or compiler bug?

Are you compiling both files?

dmd file1.d d3d8.d

Actually, if this isn't a typo, the error references file2.obj, but I only see file1.d.


February 27, 2007
Jarrett Billingsley wrote:
> "Neal Alexander" <wqeqweuqy@hotmail.com> wrote in message news:erv3kf$2ukm$1@digitalmars.com...
>> The IDirect3D8 interface works fine if its used opaquely with the various directx routines; but when the interface is used to make a class that implements it, or in this case wraps it, the linker cant find the IDirect3D8 interface symbol.
>>
>> Scope issues or compiler bug?
> 
> Are you compiling both files?
> 
> dmd file1.d d3d8.d
> 
> Actually, if this isn't a typo, the error references file2.obj, but I only see file1.d. 
> 
> 

Yea, file2 is some other code that isn't hugely relevant. Anyway, I tried compiling d3d8.d in with it, but it gives 'multiple defined' type errors during the parsing stage since the module is imported i guess (cant build without the type definitions in it). d3d8.d is just a "header" anyway it shouldn't need to be explicitly compiled right? Also, i don't understand why an interface definition produces a symbol in the binary haha.

I was thinking, maybe it could also be an issue with symbol naming - maybe extern (Windows) isnt matching up for everything -- but i tried playing with different extern () settings and it diddnt help.

I uploaded the full d3d8.d; incase someone wanted to take a look. Its relatively small compared to some of the other D3D headers haha.

http://arenz.game-host.org:8080/d3d8.d.txt
February 27, 2007
"Neal Alexander" <wqeqweuqy@hotmail.com> wrote in message news:es053h$19iq$1@digitalmars.com...
>
> Yea, file2 is some other code that isn't hugely relevant.

Well, the error is referring to file2.d, so my guess is that the problem is there.  Would help if I knew what was in it.

> Anyway, I tried compiling d3d8.d in with it, but it gives 'multiple defined' type errors during the parsing stage since the module is imported i guess (cant build without the type definitions in it).

This is because you've named the file d3d8.d, but the module statement at the top says "module directx".  If you put different things for the filename and for the module declaration, weird things result, so that should read "module d3d8" instead.

> d3d8.d is just a "header" anyway it shouldn't need to be explicitly compiled right? Also, i don't understand why an interface definition produces a symbol in the binary haha.

I think you do need to compile it, because even though IDirect3D8 is just an interface, it's a different kind of interface, a COM interface.  COM interfaces don't work quite the same way as D interfaces.  When you derive a D class from a COM interface, D seems to create a "shim" interface so that the class can implement the interface, and that shim is what's actually being inserted into the symbol table, and is what D needs.

In fact, I just worked up a simple example just now, and this seems to be exactly what's happening:

[-------------dtest.d--------------]
module dtest;

import comtest;
import std.c.windows.com;

pragma(lib, "uuid.lib");

class Foo : ComObject, IFoo
{

}

void main()
{

}

[-----------comtest.d--------------]
module comtest;

import std.c.windows.com;

interface IFoo : IUnknown
{

}


Now, when I compile with the command line

dmd dtest.d

I get the error

dtest.obj(dtest)
 Error 42: Symbol Undefined _D7comtest4IFoo11__InterfaceZ

Hm.  So I compile with

dmd dtest.d comtest.d

and it compiles fine.


February 27, 2007
Works perfectly now, thanks for the help.


> This is because you've named the file d3d8.d, but the module statement at the top says "module directx".  If you put different things for the filename and for the module declaration, weird things result, so that should read "module d3d8" instead.

Yea i had tried module d3d8 earlier and it diddn't work, but i realized the file
was in the system include folder so i had to put std.c.windows.blah.blah.d3d8