Ohhh arise extern wizards! Want silencePlayers in bzflag.cxx

Questions or HOWTOs about the above? Post 'em here...
Post Reply
michaelh20
Private First Class
Private First Class
Posts: 57
Joined: Thu Dec 12, 2002 2:28 am
Location: MN USA

Ohhh arise extern wizards! Want silencePlayers in bzflag.cxx

Post by michaelh20 »

am trying to access the SilenceList silencePlayer in playing.cxx *in* dumpResources() which is part of bzflag.cxx so I can dump the list into the resources database (more or less).


I have done this numberous ways, all of which result in an undefined symbol link error (VC++)

My current iteration has nothing in bzflag.cxx,
moved BZF_DEFINE_ALIST(SilenceList, BzfString);
into playing.h (which is included into bzflag.cxx, right?),
Then I added the following to playing,h
class SilenceList; //?
extern SilenceList silencePlayers; //?

Then I have static SilenceList silencePlayers; in playing.cxx....


I think this would made SilenceList global in all the files, which is not needed. And I would think all I would need would be to define the list class in playing.h and extern SilenceList silencePlayers in bzflag.cxx, and then I should be able to use SilenceList in bzflag.cxx and have it be the one from playing.cxx...

But.. this -------> undefined symbol error in linking which is driving me wonkers. Am I missing something about how the files are put together? Does being a macro do something here?

Tried using extern SilenceList * silencePlayers --> did NOT work
michaelh20
Private First Class
Private First Class
Posts: 57
Joined: Thu Dec 12, 2002 2:28 am
Location: MN USA

Post by michaelh20 »

Ok... so I can make a function SilenceList getSilenceList(); and declare it extern in the other file and it works. But.. I can't actually get the variable itself.






O.. k.....
User avatar
purple_cow
Private First Class
Private First Class
Posts: 63
Joined: Sun Dec 15, 2002 9:24 pm

Post by purple_cow »

I suggest you make these changes to the latest CVS. AList has all been replaced with std::vector, so it should make things easier.
michaelh20
Private First Class
Private First Class
Posts: 57
Joined: Thu Dec 12, 2002 2:28 am
Location: MN USA

Post by michaelh20 »

Drat....

already almost done :(
badger
Private First Class
Private First Class
Posts: 6
Joined: Tue Dec 24, 2002 10:31 pm
Location: Berkeley, CA, USA

Re: Ohhh arise extern wizards! Want silencePlayers in bzflag

Post by badger »

michaelh20 wrote:Then I added the following to playing,h
class SilenceList; //?
extern SilenceList silencePlayers; //?

Then I have static SilenceList silencePlayers; in playing.cxx....
you know the purpose of `static' at file scope is to hide a symbol from the linker. no amount of `extern' is going to change that. did you try removing `static' from the line in playing.cxx?

p.s. i'm guessing that your getSlienceList() function was visible because you didn't declare it static. i.e. you did

Code: Select all

  SilenceList& getSilenceList();
not

Code: Select all

  static SilenceList& getSilenceList();
it's the missing static not the extern in another file that makes it work.
Post Reply