This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: template with friend function problem
Dear Martin and Alexandre,
Thank you for your answers.
I am very sorry to confuse you. But now I managed to compile everything.
The example I sent was not fully working program. I sent it because I
thought
that I missed something in the instantiation of friend functions.
I would try to explain what happened, though it is for sure my falt but not
gcc.
My library contains templates. Some instances of those templates are
already used
inside the library.
I compile library, then I try to compile a program with this library.
gcc says something like this
libfoo.so: undefined reference to FooClass<float>::memberFunction(void)
libfoo.so: undefined reference to void
friendFunctionOfClassFoo<float>(void)
Note that these error refer to the library but not to program that uses
that library
Then I try to instantiate those functions explilictly in the special file
instantiate.cpp:
template void FooClass<float>::memberFunction(void);
template void friendFunctionOfClassFoo<float>(void);
I compile instantiate.cpp and link it with libfoo.so
But I DO NOT recompile the other object file that compose libfoo.so
I try to compile my program again with the library libfoo.so and
get only one error that refers to friendFunctionOfClassFoo<float>(void).
The error for member function disappears (!):
libfoo.so: undefined reference to void
friendFunctionOfClassFoo<float>(void)
Finally I recompiled the WHOLE library with necessary explicit
instantiation
in the file instantiate.cpp and it was successfull !!!
I am not sure that my explanation is enough for you to understand MY(!)
error.
Anyway , sorry for disturbance.
Vladimir
"Martin v. Loewis" wrote:
> > So, unless instantiation.o was not included in library, there is a bug
> > in gcc.
>
> I tried compiling the example myself now. The declaration of
> CoolBaseVector was missing, so I assumed an empty class. With that,
> gcc 2.95.2 gives my an assembler file that contains
>
> cross_3d__H1Zf_RCt10CoolVector1ZX01T0_t10CoolVector1ZX01
>
> IOW, I could not reproduce any problem...
>
> Regards,
> Martin