From owner-freebsd-current Fri Mar 17 12:31:03 1995 Return-Path: current-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id MAA09202 for current-outgoing; Fri, 17 Mar 1995 12:31:03 -0800 Received: from estienne.cs.berkeley.edu (estienne.CS.Berkeley.EDU [128.32.42.147]) by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id MAA09194; Fri, 17 Mar 1995 12:31:01 -0800 Received: from localhost (localhost [127.0.0.1]) by estienne.cs.berkeley.edu (8.6.9/8.6.9) with SMTP id MAA16609; Fri, 17 Mar 1995 12:31:00 -0800 Message-Id: <199503172031.MAA16609@estienne.cs.berkeley.edu> X-Authentication-Warning: estienne.cs.berkeley.edu: Host localhost didn't use HELO protocol To: nate@FreeBSD.org cc: current@FreeBSD.org Subject: Patch for gcc Date: Fri, 17 Mar 1995 12:30:59 -0800 From: "Justin T. Gibbs" Sender: current-owner@FreeBSD.org Precedence: bulk On of the professors I work for pointed this out to me: Begin Forwarded Message ----------------------- Gcc v2.6.3 currently has a problem with templates. Specifically, with default switches, template functions get EXTERNAL linkage in each file in which they occur, causing multiple definition errors during linking. The enclosed patch (from gnu.g++.bug) appears to solve the problem (I enclose the accompanying message as well). It would be nice to install this in /usr/local/bin. Paul - -------------------------------------------------- Article: 14433 of gnu.g++.bug From: rjl@iassf.easams.COM.AU (Rohan LENARD) Newsgroups: gnu.g++.bug Subject: Re: Multiple Method Definitions in Templates Date: 8 Mar 1995 17:23:44 -0500 Organization: GNUs Not Usenet Lines: 136 Sender: daemon@cis.ohio-state.edu Approved: bug-g++@prep.ai.mit.edu Distribution: gnu Message-ID: <0jLUto3_3gX_0Ak1g0@iassf.easams.com.au> References: <10330.794622376@N2.SP.CS.CMU.EDU> Hi there, Thanks for the bug report. I forgot to supply the patch for this problem in my previous mail. Here it is - Regards, Rohan - ------------------------------------------------------------------------ (Thanks to Jason Merrill at cygnus support). This patch fixes the multiply defined template functions bug which was introduced in 2.6.1. Jason *** ../../gcc-2.6.3/cp/pt.c Mon Nov 14 23:34:29 1994 - --- pt.c Mon Dec 12 21:10:06 1994 *************** *** 2302,2307 **** - --- 2302,2311 ---- else if (! flag_implicit_templates) DECIDE (0); + if (i->interface == 1) + /* OK, it was an implicit instantiation. */ + TREE_PUBLIC (t) = 0; + /* If it's a method, let the class type decide it. @@ What if the method template is in a separate file? Maybe both file contexts should be taken into account? - ------------------------------------------------------------------------ Excerpts from BugReport.Gnu: 7-Mar-95 Multiple Method Definitions.. Peter_Stephan@n2.sp.cs.c (2274) > I encountered a situation which I believe is a bug. It occurs > in version 2.6.3 of g++ on both DEC Alphas running OSF1 v2.0 and > SUN4s running SunOS v4.1.3. > The situation occurs when using a C++ template in two or more > modules which are ultimately linked together and is similar to another > bug report that I have just submitted. As seen in the brief examples > below, I have defined a templated class, dv, with a method print. I have > also defined a version of the print method specifically for instantiations > of this template with . The linker identifies the print method as > being multiply defined. If there is only one module to this system, it > seems to work fine. When the example code given is compiled and linked, > the following output results: > pheasant <278> g++ -fexternal-templates -c prog1.C -o prog1.o > pheasant <279> g++ -fexternal-templates -c prog2.C -o prog2.o > pheasant <280> g++ -fexternal-templates prog1.o prog2.o -o prog > ld: prog2.o: _print__t2dv1Zc: multiply defined > collect2: ld returned 2 exit status > This problem was not exhibited when using g++ version 2.5.8 on the > same platforms without the #pragma and -fexternal-templates stuff. > Any information would be appreciated. > Thank you, > Peter > --- > Peter Stephan CMU School of Computer Science > pstephan@cs.cmu.edu Wean Hall Room 7106 > Research Programmer (412) 268-7663 > /***** prog.h ******/ > #pragma interface > #include > template class dv { > public: > dv(TYPE d) { > data = d; > } > ~dv() {} > void print(); > private: > TYPE data; > }; > template void dv::print() { > cout << "Data = " << "." << data << "\n"; > return; > } > void dv::print() { > cout << "Char = " << data << ".\n"; > return; > } > /***** end of prog.h ******/ > /***** prog1.C *****/ > #pragma implementation "prog.h" > #include "prog.h" > extern void another_routine(); > main() { > dv vi(8); > dv vc('z'); > vi.print(); > vc.print(); > another_routine(); > cout << "Normal program termination." << endl; > } > /***** end of prog1.C *****/ > /***** prog2.C *****/ > #include "prog.h" > void another_routine() { > dv vi(1); > vi.print(); > cout << "Finished in another_routine." << endl; > } > /***** end of prog2.C *****/ ------- End of Forwarded Message