C++ static member function reported as undefined references by linker?
David Cespedes
David.Cespedes@i-o.com
Thu Oct 27 16:16:00 GMT 2005
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
More information about the Gcc-help
mailing list