|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (7 bit)
Join Date: Jul 2000
Location: Australia
Posts: 97
|
I've got a static variable declared global to a file . Now whenever I link, the linker complains that it cannot resolve the static variable. If I remove the static qualifier everything links properly.
Any ideas why this is happening? All help appreciated. |
|
|
|
|
|
#2 |
|
Member (8 bit)
Join Date: Jul 1999
Posts: 141
|
Perhaps if you print some of the code, how it looks with the static qualifier and how it looks without it, it may be easier to help.
I think I have an idea of what you are talking about but I'm not sure. [Edited by TechTeach on 12-15-2000 at 03:13 PM] |
|
|
|
|
|
#3 |
|
Member (7 bit)
Join Date: Jul 2000
Location: Australia
Posts: 97
|
Hi Teach, this is not the exact code ( the company I'm working for is very strict about releasing code and it a small part of a very large code ). By the way I only get link errors on release mode where the code is optimized.
If I include debug information everything is fine. When building the release version ( no debug info ) I've tried using the option -O1 lowest optimisation, plus added volatile qualifier on the variables mentioned below but I still have link errors. Okay here goes, I've got this variables declared in a CPP file. typedef struct { int32 id; const char *errStr; } EventStruct; static EventStruct *gEventTable = NULL; static int gSize = 0; static bool gEchoOn = false; The file also contains an inline class which access the variables mentioned above which inherits from an abstract class which is on another separate file. class Abstract : public Concrete { public : . . void Access_g_EventTable() { if ( gEventTable ) { ( do what ever here also manipulate or access gSize and gEcho here ) } } } Now there is also a stand alone function which initialises the mentioned variable. This is declared as extern in another file where EventStruct is created. After EventStruct is created this function is called passing in the newly created EventStruct. void setVarialbes( EventStruct* eventTable, int size ) { gEventTable = eventTable; gSize = size; } In NT ( This code is designed to run on multiple OS ) everything is OK (Debug and Release version ), but in Solaris I get a link error ( only when debugging is off ) saying that the variable gEventTable, gSize and gEchoOn is unreferenced in the file where they were declared. Sorry if this is a bit long and I could not give all of the code. |
|
|
|
|
|
#4 |
|
Member (12 bit)
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
|
I don't see why you need to use the static keyword at all... Maybe I'm not thinking right as it's 3:30 AM here, but I don't think I've ever seen static variables used outside of a class/struct.
The only reason I know of to use static variables is, when used before a data member in a class, it forces the value of that data member to be the same amongst all instances of the class. I.e., if you use this code:
By definition any global variable will always act this way -- as there can be only one instance of the global variable -- so what, then, is the static supposed to do, anyhow? Maybe if I knew why you needed it, I could offer more advice. (Sorry, BTW, if this makes no sense, or is really dumb. It's 3:30 AM, that's my excuse and I'm sticking to it) [Edited by Paul Victorey on 12-30-2000 at 04:40 AM]
__________________
Paul M. Victorey ------------------ I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk. |
|
|
|
|
|
#5 |
|
Member (7 bit)
Join Date: Jul 2000
Location: Australia
Posts: 97
|
Hi Paul,
Sorry for the late reply, I been out of the net for a while. Youre right, I've already solved this problem by removing the static qualifier and everything runs OK. My excuse is, the code was not mine and I was just porting it from NT to Solaris .Thanks for all the responses and cheers! |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|