From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27954 invoked by alias); 27 Oct 2005 18:38:08 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 27878 invoked by uid 22791); 27 Oct 2005 18:37:57 -0000 Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (199.232.76.164) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Thu, 27 Oct 2005 18:37:57 +0000 Received: from monty-python.gnu.org ([199.232.76.173]) by fencepost.gnu.org with esmtp (Exim 4.34) id 1EVCdO-0002vh-Lo for gcc-help@gnu.org; Thu, 27 Oct 2005 14:37:54 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1EVCdO-0003ZU-FI for gcc-help@gnu.org; Thu, 27 Oct 2005 14:37:55 -0400 Received: from [209.163.254.3] (helo=digiexch02.iodigi.ioroot.tld) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EVCdO-0003ZP-6I for gcc-help@gnu.org; Thu, 27 Oct 2005 14:37:54 -0400 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: C++ static member function reported as undefined references by linker? Date: Thu, 27 Oct 2005 18:38:00 -0000 Message-ID: <764B61E47816BC47B59D1A8B15DF01070C048D@digiexch02.iodigi.ioroot.tld> From: "David Cespedes" To: "corey taylor" , X-SW-Source: 2005-10/txt/msg00203.txt.bz2 If inside a namespace, yes. But not inside a class, unless the class is inside a namespace. See the ARM (Annotated Reference Manual), Sec 9.4: "Static members of a global class have external linkage." -----Original Message----- From: corey taylor [mailto:corey.taylor@gmail.com]=20 Sent: Thursday, October 27, 2005 1:07 PM To: David Cespedes; gcc-help@gnu.org Subject: Re: C++ static member function reported as undefined references by linker? This is according to the C++ specification. Check out section 3.5 (Program and Linkage) of the 14882:2003 specification. Corey On 10/27/05, David Cespedes wrote: > You are right, it worked. Is this an artifact of the gcc? I am nit sure > this is 100% compliant with the C++ spec. I see this as a work around, > thank you for all the help > > Regards > Daveed > > -----Original Message----- > From: corey taylor [mailto:corey.taylor@gmail.com] > Sent: Thursday, October 27, 2005 12:30 PM > To: David Cespedes > Subject: Re: C++ static member function reported as undefined references > by linker? > > You will automatically get external linkage when declared inside of a > named namespace. > > corey > > On 10/27/05, David Cespedes wrote: > > Well show does a class have external linkage? I though this was the > > default? Please show me an example. > > > > Regards, > > Daveed > > > > -----Original Message----- > > From: corey taylor [mailto:corey.taylor@gmail.com] > > Sent: Thursday, October 27, 2005 11:40 AM > > To: David Cespedes > > Cc: gcc-help@gcc.gnu.org > > Subject: Re: C++ static member function reported as undefined > references > > by linker? > > > > David, > > > > As far as I know, they only have external linkage if the class has > > external linkage. > > > > Corey > > > > On 10/27/05, David Cespedes wrote: > > > Can you help with this issue, in regards to C++ static member > > functions and why they are reported as undefined references by the > > linker? > > > > > > Please see attached email trail! > > > > > > Best Regards > > > Daveed > > > ________________________________________ > > > From: Paul > > > Sent: Thursday, October 27, 2005 10:40 AM > > > To: David Cespedes > > > Subject: RE: Linux C++ implementation > > > > > > I don't know enough about Linux/gcc to help. > > > static members are supposed to have external linkage--ARM Sec 9.4 > > > > > > ________________________________________ > > > From: David Cespedes > > > Sent: Thursday, October 27, 2005 11:46 AM > > > To: Paul > > > Subject: RE: Linux C++ implementation > > > Yes, I did! I have a Sample.h for the definition and Sample.cpp > where > > there is a void CSample::test(unsigned char foo) { ... } > implementation. > > > > > > The only work-around I found is to implement the method function in > > the definition .H file (inline it) and I must declare the static > member > > as an "extern bool CSample::m_bState" in order to see it, from an > > outside scope. > > > > > > ________________________________________ > > > From: Paul > > > Sent: Thursday, October 27, 2005 10:40 AM > > > To: David Cespedes > > > Subject: RE: Linux C++ implementation > > > > > > Did you define (implement) the function somewhere? > > > gcc is a very good compiler, I'm sure it follows all the standards. > > > > > > ________________________________________ > > > From: David Cespedes > > > Sent: Thursday, October 27, 2005 11:02 AM > > > To: Paul > > > Subject: Linux C++ implementation > > > Hi Paul! > > > > > > Once again I see myself baffled by a C++ questions and you are my > last > > source for an educated answer. Anyhow, I have just started developing > > under the Linux platform using the gcc 2.96; do not ask why that > version > > I do not control it. > > > > > > So I am working along and, by now, C++ is supposed to be C++ on any > > platform, until I declare a static method function and member in a > > class; see sample code. When I do this, if I try to use the global > scope > > CSample::Test(...), the linker tells me that the function is an > > undefined reference??? > > > > > > What happen here are? Did then gcc folks confuse the "C" vs. "C++" > > interpretation of a static scope? I need help... > > > > > > class CSample > > > { > > > public: > > > CSample(); > > > ~CSample(); > > > static void test(unsigned char foo); > > > > > > protected: > > > static bool m_bState; > > > }; > > > > > > Best regards, > > > > > > ________________________________________ > > > David A. Cespedes > > > Chief Software Engineer - Manager > > > I/O Marine Imaging Systems Division > > > Office: 281.879.2171 > > > > > > > > >