public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: C++ static member function reported as undefined references by linker?
@ 2005-10-27 18:38 David Cespedes
  2005-10-27 18:47 ` corey taylor
  0 siblings, 1 reply; 8+ messages in thread
From: David Cespedes @ 2005-10-27 18:38 UTC (permalink / raw)
  To: corey taylor, gcc-help

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] 
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 <David.Cespedes@i-o.com> 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 <David.Cespedes@i-o.com> 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 <David.Cespedes@i-o.com> 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
> > >
> > >
> >
>

^ permalink raw reply	[flat|nested] 8+ messages in thread
[parent not found: <764B61E47816BC47B59D1A8B15DF01070C0488@digiexch02.iodigi.ioroot.tld>]
* C++ static member function reported as undefined references by linker?
@ 2005-10-27 16:16 David Cespedes
  2005-10-27 16:40 ` corey taylor
  2005-11-05 20:55 ` Nathan Sidwell
  0 siblings, 2 replies; 8+ messages in thread
From: David Cespedes @ 2005-10-27 16:16 UTC (permalink / raw)
  To: gcc-help

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
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-11-05 21:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <764B61E47816BC47B59D1A8B15DF01070C0492@digiexch02.iodigi.ioroot.tld>
2005-10-28 15:39 ` C++ static member function reported as undefined references by linker? corey taylor
2005-10-27 18:38 David Cespedes
2005-10-27 18:47 ` corey taylor
     [not found] <764B61E47816BC47B59D1A8B15DF01070C0488@digiexch02.iodigi.ioroot.tld>
2005-10-27 18:06 ` corey taylor
  -- strict thread matches above, loose matches on Subject: below --
2005-10-27 16:16 David Cespedes
2005-10-27 16:40 ` corey taylor
2005-11-05 20:55 ` Nathan Sidwell
2005-11-05 21:23   ` corey taylor

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).