help-gplusplus
[Top][All Lists]
Advanced

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

Re: Undefined references to variable problem


From: Robert Heller
Subject: Re: Undefined references to variable problem
Date: Sun, 28 Aug 2005 20:02:35 +0200

  "Brian Arnold" <brianarn@gmail.com>,
  In a message on 28 Aug 2005 10:44:14 -0700, wrote :

"A> Hello,
"A> 
"A> This is my first usenet posting, so please be gentle. :)
"A> 
"A> I have a very odd issue with some fairly simple code I'm trying to get
"A> working. In one of my headers, I have the line:
"A> 
"A>   static size_t _sharkcount;
"A> 
"A> and if I reference that variable through other functions and whatnot,
"A> things are fine. However, if I add a new variable in that header,
"A> immediately below that one, with the name of
"A> 
"A>   static size_t _supersharkcount;
"A> 
"A> or really, *any* other name (tried _foo and _rippingmydamnhairout), and
"A> try to reference that one, I have linking issues. Everything compiles
"A> just fine, but in linking my object files together, I get a few of:

*Somewhere* in one of your C++ files is a line like:

size_t Object::_sharkcount;

You need to add a line like:

size_t Object::_supersharkcount;

There as well.

"A> 
"A> 
Object.o:Object.C:(.text$_ZN10SuperSharkD0Ev[SuperShark::~SuperShark()]+0x40):
"A> undefined reference to `Object::_supersharkcount'
"A> 
Object.o:Object.C:(.text$_ZN10SuperSharkD0Ev[SuperShark::~SuperShark()]+0x78):
"A> undefined reference to `Object::_supersharkcount'
"A> 
Object.o:Object.C:(.text$_ZN10SuperSharkD1Ev[SuperShark::~SuperShark()]+0x48):
"A> undefined reference to `Object::_supersharkcount'
"A> 
Object.o:Object.C:(.text$_ZN10SuperSharkD1Ev[SuperShark::~SuperShark()]+0x77):
"A> more undefined references to `Object::_supersharkcount' follow
"A> collect2: ld returned 1 exit status
"A> 
"A> I also get another error in a World.o file that uses a function that
"A> hits _supersharkcount.
"A> 
"A> If I change my destructor (and other points in the code) to hit
"A> _sharkcount instead of _supersharkcount, then I don't get all of these
"A> undefined references. However, adding this one other static variable
"A> (which is in the protected space of my Object class) causes the linking
"A> to fail.
"A> 
"A> I've been all over Google and looking through various newsgroups, and I
"A> find specific instance problems, such as getting the undefined
"A> references when compiling very specific programs, but I can't find
"A> anything that seems to relate to my problem here.
"A> 
"A> I've tried compiling this with g++ 3.4.4 in Cygwin on a WinXP box, g++
"A> 3.3.5 on  a Debian box, and g++ 3.4.2 on a FreeBSD box. While the
"A> verbiage in the location within .text is different, it's all the same
"A> message, saying I have an undefined reference to
"A> Object::_supersharkcount, during the linking. The code itself compiles
"A> fine all over.
"A> 
"A> I would greatly appreciate any information that could be provided to
"A> me. Thank you so much for your help.
"A> 
"A>                            

                                     \/
Robert Heller                        ||InterNet:   heller@cs.umass.edu
http://vis-www.cs.umass.edu/~heller  ||            heller@deepsoft.com
http://www.deepsoft.com              /\FidoNet:    1:321/153






                                     


reply via email to

[Prev in Thread] Current Thread [Next in Thread]