compiling templates with g++
llewelly@198.dsl.xmission.com
llewelly@198.dsl.xmission.com
Thu Dec 23 13:02:00 GMT 1999
Only put definitions of *templated* functions in the header file; put all
other definitions in .cc files as usual.
On Thu, 23 Dec 1999, Amit Mehrotra wrote:
> But if I use this code in multiple source files, all of those which include
> the header file with the implementation, the linker complains about
> duplicate definitions!
I do this all the time, and I don't get these complaints.
I am using gcc 2.95.2, binutils 2.9.1, on i686-pc-linux-gnu
>
> Amit
>
> > Put the definitions of your template functions in your header file.
> >
> > If this causes problems, run 'info gcc' and then type 'gTemplate Instantiation'
> > (info will tab-complete, like bash and tcsh).
> >
> > gcc does not yet support having a definition of a templated function in a
> > compilation unit separate from where it is used.
>
> > ANSI C++ requires a definition of a templated function to be declared
> > 'export' for it to be availible to other compiliation units, but, as I
> > said before, gcc doesn't support that yet.
>
More information about the Gcc-help
mailing list