From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15290 invoked by alias); 1 Jun 2011 13:23:31 -0000 Received: (qmail 15282 invoked by uid 22791); 1 Jun 2011 13:23:30 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 01 Jun 2011 13:23:16 +0000 Received: from hpaq7.eem.corp.google.com (hpaq7.eem.corp.google.com [172.25.149.7]) by smtp-out.google.com with ESMTP id p51DNF35019491 for ; Wed, 1 Jun 2011 06:23:15 -0700 Received: from yia27 (yia27.prod.google.com [10.243.65.27]) by hpaq7.eem.corp.google.com with ESMTP id p51DMM3m002686 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Wed, 1 Jun 2011 06:23:14 -0700 Received: by yia27 with SMTP id 27so2196173yia.19 for ; Wed, 01 Jun 2011 06:23:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.91.201.4 with SMTP id d4mr6396763agq.41.1306934593877; Wed, 01 Jun 2011 06:23:13 -0700 (PDT) Received: by 10.91.212.14 with HTTP; Wed, 1 Jun 2011 06:23:13 -0700 (PDT) In-Reply-To: <20110601084446.GQ13140@axel> References: <7758AFD4380CD24F86D3266E0D083A0550544AF1C8@GVW1160EXB.americas.hpqcorp.net> <7758AFD4380CD24F86D3266E0D083A0550544AF93B@GVW1160EXB.americas.hpqcorp.net> <7758AFD4380CD24F86D3266E0D083A0550544AFE4D@GVW1160EXB.americas.hpqcorp.net> <20110601084446.GQ13140@axel> Date: Wed, 01 Jun 2011 13:23:00 -0000 Message-ID: Subject: Re: Undefined reference to template function ... From: Ian Lance Taylor To: "Her, Il" , Ian Lance Taylor , "gcc-help@gcc.gnu.org" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg00012.txt.bz2 On Wed, Jun 1, 2011 at 1:44 AM, Axel Freyn 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=3D/tmp/gcc_test/install --disable-multilib > Thread model: posix > gcc version 3.4.6 > > your testcase gives =A0(after removing the erroneous ";" in sub.cpp ) > > /tmp/ccGJf1zv.o: In function `main': > /tmp/gcc_test/main.cpp:9: undefined reference to `Base::dump(TEST&)' > /tmp/gcc_test/main.cpp:10: undefined reference to `Base::fn(int, in= t)' > collect2: ld returned 1 exit status I just did the same thing on x86_64-unknown-linux-gnu, with the same result= s. 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, a= nd 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