linker: undefined symbol when an interface is derived from.

Jarrett Billingsley kb3ctd2 at
Mon Feb 26 20:35:58 PST 2007

"Neal Alexander" <wqeqweuqy at> wrote in message 
news:es053h$19iq$1 at
> 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:

module dtest;

import comtest;

pragma(lib, "uuid.lib");

class Foo : ComObject, IFoo


void main()


module comtest;


interface IFoo : IUnknown


Now, when I compile with the command line

dmd dtest.d

I get the error

 Error 42: Symbol Undefined _D7comtest4IFoo11__InterfaceZ

Hm.  So I compile with

dmd dtest.d comtest.d

and it compiles fine. 

More information about the Digitalmars-d-learn mailing list