This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: template code yields (almost) no asm output


> example error (several pages, an error for each instance of this
> templated class in my code... btw this is during the link stage, as
> ***g++ outputs no errors during compilation***)
> 
> library_llist.o: In function `ExtractType(LList<SharedLibrary> *, char
> *, int)':
> /home/Zetta/War/War/new/library_llist.cpp:7: undefined reference to
> `LList<SharedLibrary>::LList(void)'

Thanks for your bug report. You did not provide the source for
library_llist, but I suspect the bug is in your code. 

There is a couple of things I noticed:

a) The declaration of template<class>class LList is apparently in an
   implementation file llist.cpp. How come that library_llist.cpp
   knows what this declaration is? Do you have a second copy of that
   declaration? That would be bad.

b) I'm not surprised that g++ does not generated any code in llist.s.
   You are not instantiating the template, and you get code only for
   template instantiations. So, in order to generate code for
   LList<SharedLibrary>, the compiler needs to see both LList and
   SharedLibrary at the same time. More formally, a template class or
   member of template class must be defined at the point of
   instantiation of the template. Most likely, this is not the case in
   your code; make sure the template code is defined in a header file.
   Perhaps you were using a compiler that accepted your code. This was
   an extension of the C++ standard in that compiler.

Hope this helps,
Martin



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]