templates undefined reference

Henning Hasemann hhasemann at web.de
Wed Jun 20 14:55:31 PDT 2007


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

-- 
GPG Public Key:
http://keyserver.ganneff.de:11371/pks/lookup?op=get&search=0xDDD6D36D41911851
Fingerprint: 344F 4072 F038 BB9E B35D  E6AB DDD6 D36D 4191 1851


More information about the Digitalmars-d-learn mailing list