Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-Id: <199911170557.XAA16371@mercury.xraylith.wisc.edu> To: "Chalapathi R. Emani" cc: cygwin AT sourceware DOT cygnus DOT com Subject: Re: Linking problems with templates. In-Reply-To: Your message of "Tue, 16 Nov 1999 15:40:29 PST." <4 DOT 1 DOT 19991116152035 DOT 00aa6060 AT clea DOT qualcomm DOT com> Date: Tue, 16 Nov 1999 23:57:36 -0600 From: Mumit Khan "Chalapathi R. Emani" writes: > > Hi, > > I am trying to use the latest version from cygwin and > I am having linking problems with a file that uses templates: > > When I compiled one of the source file I got the following warnings: > > Config.h:178: warning: friend declaration `class istream & operator >>(class > ream &, class OrderedTriple &)' > Config.h:178: warning: declares a non-template function > Config.h:178: warning: (if this is not what you intended, make sure > Config.h:178: warning: the function template has already been declared, > Config.h:178: warning: and add <> after the function name here) > Config.h:179: warning: friend declaration `class ostream & operator > <<(class ost > ream &, class OrderedTriple &)' [ ... ] This is a change in the standard that had caught most (all?) of us who've had C++ code dating back years. You need to fix the code, and there's really no easy way out. How to keep compatibility with other compilers? Well, I usually use configure-driven systems, and I wrote a simple autoconf macro (now also used by other packages such as GNU Octave) that checks for if your C++ compiler supports friend template declaration or not, and if not, defines a pre-processor macro to support older compilers (such as GCC-2.8.1 or MSVC 6.x). I believe this was added in egcs-1.1 (egcs-2.91.57), but I may be off by a release. Here's an example: # ifdef CXX_NO_FRIEND_TMPL_DECL # define LTGT # else # define LTGT <> # endif Then in the code: // must forward class and friend functions template class Foo; template Foo& operator += (Foo&, const T&); template class Foo { public: // ... friend Foo& operator += LTGT (Foo&, const T&); // ... }; For new compilers, nothing needs to be done. For old ones, define the macro CXX_NO_FRIEND_TMP_DECL when compiling. > > I went ahead and compiled this with the flag "-fguiding-decls" and these > warnings have gone away. > Then I tried linking this with the rest of the objects and libstdc++.a and > I am getting the following > errors: Well, unfortunately -fguiding-decls really doesn't work when there are libraries involved. I suppose with lots of extra work, it could be made to work always, but I doubt it'll be done unless someone contributes the changes. > > On Solaris when I use the "-fguiding-decls" option and compile and link > it, it builds just fine. > May be because I use 2.8.1 on Solaris. 2.8.1 didn't really support many of the new C++ standard features, so it's not surprising. > > Do you know if the above option has been deprecated in Cygwin 2.95.2 ? > Not deprecated, just full of pitfalls. For more details of template friends, see Section 14.5.3 [temp.friend]/1 in the C++ ISO standard document. Regards, Mumit -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com