This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Undefined reference to template function ...
- From: Ian Lance Taylor <iant at google dot com>
- To: "Her, Il" <il dot her at hp dot com>, Ian Lance Taylor <iant at google dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 1 Jun 2011 06:23:13 -0700
- Subject: Re: Undefined reference to template function ...
- References: <7758AFD4380CD24F86D3266E0D083A0550544AF1C8@GVW1160EXB.americas.hpqcorp.net> <mcry61ns9mq.fsf@coign.corp.google.com> <7758AFD4380CD24F86D3266E0D083A0550544AF93B@GVW1160EXB.americas.hpqcorp.net> <mcrhb8brna9.fsf@coign.corp.google.com> <7758AFD4380CD24F86D3266E0D083A0550544AFE4D@GVW1160EXB.americas.hpqcorp.net> <20110601084446.GQ13140@axel>
On Wed, Jun 1, 2011 at 1:44 AM, Axel Freyn <axel-freyn@gmx.de> wrote:
> Hi
>
> On Wed, Jun 01, 2011 at 01:03:03AM +0000, Her, Il wrote:
>> Yes, it is compiled well with gcc 3.4.6,
>> but it doesn't work with gcc 4.1.2
>
> Strange -- I just tried with 3.4.6 on x86_64, configured as
> ../gcc-3.4.6/configure --prefix=/tmp/gcc_test/install --disable-multilib
> Thread model: posix
> gcc version 3.4.6
>
> your testcase gives ?(after removing the erroneous ";" in sub.cpp )
>
> /tmp/ccGJf1zv.o: In function `main':
> /tmp/gcc_test/main.cpp:9: undefined reference to `Base<TEST>::dump(TEST&)'
> /tmp/gcc_test/main.cpp:10: undefined reference to `Base<TEST>::fn(int, int)'
> collect2: ld returned 1 exit status
I just did the same thing on x86_64-unknown-linux-gnu, with the same results.
Looking at the code, I don't see how the results could be anything
else. You need
to force the template expansion to occur as described on the web page
referenced earlier on the thread.
Also looking at the code, it did not compile, due to the extra semicolon, and I
had to change main.cpp to #include "test.h" rather than "TEST.h". So I don't
think you tested the exact code you showed us with gcc 3.4.6.
Ian