The solution is to include the .h file in most of the .cc files using the class, and to instantiate the template in only one compiled .cc file. The g++ info pages (accessible in emacs) describes how to do this:
Explicitly instantiate all the template instances you use, and compile with -fno-implicit-templates. This is probably your best bet; it may require more knowledge of exactly which templates you are using, but it's less mysterious than the previous approach, and it doesn't require any #pragmas or other g++-specific code. You can scatter the instantiations throughout your program, you can create one big file to do all the instantiations, or you can create tiny files likeSo if you put the above in Foo-int.cc, you should arrange for your Makefile to compile it into Foo-int.o, and link that into your code. Do not #include Foo.cc anywhere else in your code!
#include "Foo.h" #include "Foo.cc" template class Foofor each instance you need, and create a template instantiation library from those. ;