RE: C++ static member function reported as undefined references by linker?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx] 
Sent: Thursday, October 27, 2005 1:07 PM
To: David Cespedes; gcc-help@xxxxxxx
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@xxxxxxx> 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@xxxxxxxxx]
> 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@xxxxxxx> 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@xxxxxxxxx]
> > Sent: Thursday, October 27, 2005 11:40 AM
> > To: David Cespedes
> > Cc: gcc-help@xxxxxxxxxxx
> > 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@xxxxxxx> 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
> > >
> > >
> >
>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux