Strange linker error with extern variables

I have a header that declares a set of variables with the extern keyword. Then I have a cpp file responsible for getting the true declarations in. For some reason one of the variables is producing linker errors. Here is how I've done it:

(.h)
...
extern Subsystem **StaticSessions;
...

(.cpp)
...
Subsystem **StaticSessions;
...

I have them in the same namespaces, their names should match, and this is the only variable with the problem. Any ideas?
What's the error?
There are actually two, I was hoping solving the first would also solve the second but I'll give both.

1>orenNetManager.obj : error LNK2001: unresolved external symbol "struct ore::server::Subsystem * * ore::server::StaticSessions" (?StaticSessions@server@ore@@3PAPAUSubsystem@12@A)
1>LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

EDIT:
Oh got the second error, forgot to make a main. The first error is still there.
Last edited on
Ok well I fixed it by taking the actual declaration out of the .cpp it was in, and putting it in the .cpp that was causing the error. Not exactly a fix I am happy with, but at least it's compiling now.
Were you actually compiling that other CPP file? ;)
I would assume so, mainly because other global variables declared in the file are working. Just to be safe, I copied the whole thing into a new file that I was sure would compile and same issue: StaticSessions is unresolved at link time unless I put it in orenNetManager.cpp
It doesn't matter what cpp file the definitions are in as long as they're in one.

If you have definitions in one and you're still getting a linker error it's probably because the file they're in is not being linked (ie: it's not added as part of your project). Note that your IDE might not do this by default if you created the file the "wrong" way. (ie: in VS, file | new won't add it to your project, but project | add new item would).
.... It doesn't matter I have it fixed. I'm just saying I have about 10 variables that are being declared like this and this one is the only one not linking, glitch or something I don't know, but since it's working now I am going to call it fixed and move on.
Maybe you just needed to clean and rebuild the entire project? ;)
error LNK2001: unresolved external symbol "struct ore::server::Subsystem * * ore::server::StaticSessions"


It looks like your variable is declared in a namespace - are you sure that you defined it in that namespace as well?
Topic archived. No new replies allowed.