templates undefined reference

Christoph Singewald christoph at singewald.at
Sun Jun 24 04:19:12 PDT 2007


Hi!

Thanks for reply.
It does not mather if I add the template source at oompile time
e.g 
dmd -c list.d
dmd -c a.d list.d
dmd -c main.d

dmd .oftest main.o list.o a.o

Nothing changed, no template instance in a.o.

regarding to alias List!(int) IntList:

I have no problems with base type like (int, long, char, ...), but with
instances of classes, so if it would be a soulutin, I cant define for every
object an alias in the list.d. In that case I could dervivate an objectlist
from list for every object. 
  
christoph


Henning Hasemann wrote:

> Christoph Singewald <christoph at singewald.at> schrieb (Wed, 20 Jun 2007
> 22:05:25 +0200):
>> 
>> If I comile every module individually, manually or with cmake/make,
>> into an object file and link these objects files afterwards then I
>> get for every statement constructing a list an undefined reference.
>> 
>> If I compile all modules within one statment togehter then evering
>> compiles an links perfectly.
>> 
>> Does somebody know a solution?
> 
> Try putting dummy aliases in your template module. You dont even have
> to use them they serve the only purpose of having the compiler
> instanciate the template for your types.
> This is not always a good idea since it makes your import graph more
> dense and especially more likely to contain loops, but maybe it helps.
> 
> Example:
> 
> class List(T) {
>  // ...
> }
> 
> alias List!(int) IntList;
> 
> // Try to avoid this as it can lead to circular dependencies!
> import fooclass : Foo;
> alias List!(Foo) FooList;
> 
> 
> Whenever possible you should make the source of the module containing
> the template available at compile time, so the compiler can instanciate
> the template "on demand" and you dont have to define those aliases.
> 
> Henning
> 



More information about the Digitalmars-d-learn mailing list