Mail Archives: djgpp/1997/01/31/13:11:19
Mike Habicher wrote:
>
> I still can't get ld to link my multi-file
> project. The project involves a class that
> has its declarations stored in a .h file,
> which is included in two C++ files: the first
> one containing the actual code of the class'
> member functions, and the second one which is
> supposed to exercise the class to locate any
> possible coding errors.
>
> The class uses templates, and while the source
> files compile without errors, I get a whole
> bunch of "unresolved" errors when I try to link
> them together.
>
> Is there some sort of parameter I need to
> specify during the compile to get templates
> to compile properly? Or some modification I
> need to make to source files?
When I started working with DJGPP I had a similar problem with
templates, and found the solution on the gcc info file, in the section
devoted to C++ extentions.
The idea is to compile the modules with the -fno-implicit-templates
switch, and add in the file where you define the classes an explicit
declaration of the concrete instances you need.
For example, you have the template class foo:
template<class T> foo<T>
{
// all the stuff
}
// explicit instantiations for each type you need
template class foo<int>
template class foo<double>
This way it worked for me. Hope this helps!
- Raw text -