From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11947 invoked by alias); 27 Oct 2005 16:16:37 -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 11913 invoked by uid 22791); 27 Oct 2005 16:16:29 -0000 Received: from outsmtp2.i-o.com (HELO digiexch02.iodigi.ioroot.tld) (209.163.254.3) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Thu, 27 Oct 2005 16:16:29 +0000 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: C++ static member function reported as undefined references by linker? Date: Thu, 27 Oct 2005 16:16:00 -0000 Message-ID: <764B61E47816BC47B59D1A8B15DF01070C0480@digiexch02.iodigi.ioroot.tld> From: "David Cespedes" To: X-SW-Source: 2005-10/txt/msg00196.txt.bz2 Can you help with this issue, in regards to C++ static member functions and= why they are reported as undefined references by the linker? =A0 Please see attached email trail! =A0 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 =A0 ________________________________________ From: David Cespedes =A0 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. =A0 The only work-around I found is to implement the method function in the def= inition .H file (inline it) and I must declare the static member as an "ext= ern bool CSample::m_bState" in order to see it, from an outside scope. =A0 ________________________________________ From: Paul Sent: Thursday, October 27, 2005 10:40 AM To: David Cespedes Subject: RE: Linux C++ implementation =A0 Did you define (implement) the function somewhere? gcc is a very good compiler, I'm sure it follows all the standards. =A0 ________________________________________ From: David Cespedes =A0 Sent: Thursday, October 27, 2005 11:02 AM To: Paul=20 Subject: Linux C++ implementation Hi Paul! =A0 Once again I see myself baffled by a C++ questions and you are my last sour= ce 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 co= ntrol it.=20 =A0 So I am working along and, by now, C++ is supposed to be C++ on any platfor= m, until I declare a static method function and member in a class; see samp= le 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??? =A0 What happen here are? Did then gcc folks confuse the "C" vs. "C++" interpre= tation of a static scope? I need help... =A0 class CSample=20 { public: CSample(); ~CSample(); static void test(unsigned char foo); =A0 protected: static bool m_bState; }; =A0 Best regards, =A0 ________________________________________ David A. Cespedes Chief Software Engineer - Manager I/O Marine Imaging Systems Division Office: 281.879.2171 =A0