I have a static unsigned long gVar; which is global declared in server.cc file.
But when i try to use it in other file using extern unsigned long gVar; , it gives error :
unresolved external symbol "unsigned long gVar". Can you please tell me how to extern a static variable, as i am able to extern other variables from that file except this one.
You cannot use
staticandexterntogether.If you want to use the variable in other files just remove the
staticand just declare it asextern.Why you cannot use
staticandexterntogether?staticimplies Internal linkage, whileexternimplies External linkage.Internal Linkage means that the symbol is accessible only in the Translation unit in which it was declared, while External Linkage implies the symbol should be visible in all files accross your project, clearly, they are mutually exclusive.