On Fri, Nov 9, 2012 at 12:34 PM, Angelo Graziosi
<graziosi.ang...@gmail.com> wrote:
>
> $ cat foo01.cc
> #include "foo.hh"
>
> MYCLASS_INSTANTIATE_TYPES
>
> $ cat foo02.cc
> #include "foo.hh"
>
> MYCLASS_INSTANTIATE_TYPES
>
> $ cat foo.hh
>
> #define MYCLASS_INSTANTIATE(g) g(int)
>
> #define MYCLASS_INSTANTIATE_BASE(type) \
>     template class MyClassBase<type>;
>
> #define MYCLASS_INSTANTIATE_TYPES \
>   MYCLASS_INSTANTIATE(MYCLASS_INSTANTIATE_BASE)
>
> Now what happens is this:
>
> Building on *** MAC OSX *** with gcc45, gcc46, gcc47 installed by means of 
> MacPorts, fails as
>
> $ g++ foomain.o foo01.o foo02.o -o foo.out
> duplicate symbol MyClassBase<int>::ClassWrapper::ClassWrapper() in:
>     foo01.o
>     foo02.o
> duplicate symbol MyClassBase<int>::ClassWrapper::ClassWrapper() in:
>     foo01.o
>     foo02.o
> ld: 2 duplicate symbols for architecture x86_64
> collect2: error: ld returned 1 exit status
>
> instead it builds (on MAC OSX) using clang++,

This question is not appropriate for the mailing list gcc@gcc.gnu.org.
 It would be appropriate for gcc-h...@gcc.gnu.org.  Please take any
followups to gcc-help.  Thanks.

Instantiating a template creates all the instantiations in that
compilation unit.  There is no reason to instantiate a template in
more than one compilation unit.  The implementation that GCC uses does
not permit you to do that.  I don't know what LLVM does.

Ian

Reply via email to