[Debtags-devel] new libtagcoll - compilation problems

Enrico Zini zinie@cs.unibo.it
Wed, 4 Aug 2004 13:07:50 +0200


On Tue, Aug 03, 2004 at 06:39:04PM +0200, Benjamin Mesing wrote:

> > /home/ben/c++/packagesearch/src/packagesearchimpl.cpp:281: undefined reference to `Tagcoll::OpSet<int>::operator^=(Tagcoll::OpSet<int> const&)' 
> After giving it some thought the reason for this not working came back
> to me. The implementation of the template classes must be in the header
> file.
> So Enrico should probably fix this.

It's a template not being instantiated.  It took me three years to
understand how to distribute templates sanely: it's actually quite easy,
but just not that clearly documented.  If you need help about
distributing templates, ask me :)

The thing is, the OpSet<..> template is indeed in the library, but the
instantiation for the <int> datatype wasn't.  Both libraries distribute
in the include directory the .cc files containing template definitions,
which you can include to instantiate the templates you need that are not
already provided by the library.

If you have a look at the file instantiations.cc in libtagcoll or
libdebtags you can see how to instantiate templates in what I think is a
nice clean way.  The tagcoll package is another example of an
application instantiating templates for its use.

As for what I instantiate in the library, I try to be conservative and
not bloat the libraries with instantiations that people don't use.  With
this mindset I took away most instantiations of classes using an int
item, as I didn't know they could be still used after libdebtags
introduced the Package class.

I now readded some <int> template instantiations to libtagcoll trunk:
please tell me what templates you need to instantiate and if the use you
make of them is not very specific to your package, I can add them to
libtagcoll as well.

Please let me know if this solves your issue.


Ciao,

Enrico