public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "David Cespedes" <David.Cespedes@i-o.com>
To: <gcc-help@gcc.gnu.org>
Subject: C++ static member function reported as undefined references by linker?
Date: Thu, 27 Oct 2005 16:16:00 -0000	[thread overview]
Message-ID: <764B61E47816BC47B59D1A8B15DF01070C0480@digiexch02.iodigi.ioroot.tld> (raw)

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
 

             reply	other threads:[~2005-10-27 16:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-27 16:16 David Cespedes [this message]
2005-10-27 16:40 ` corey taylor
2005-11-05 20:55 ` Nathan Sidwell
2005-11-05 21:23   ` corey taylor
     [not found] <764B61E47816BC47B59D1A8B15DF01070C0488@digiexch02.iodigi.ioroot.tld>
2005-10-27 18:06 ` corey taylor
2005-10-27 18:38 David Cespedes
2005-10-27 18:47 ` corey taylor
     [not found] <764B61E47816BC47B59D1A8B15DF01070C0492@digiexch02.iodigi.ioroot.tld>
2005-10-28 15:39 ` corey taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=764B61E47816BC47B59D1A8B15DF01070C0480@digiexch02.iodigi.ioroot.tld \
    --to=david.cespedes@i-o.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).