• Advertisement

Archived

This topic is now archived and is closed to further replies.

Globals not being global enough?

This topic is 6063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey folks, I was having a little problem with trying to get my global variables to work properly, and was delighted to find Teej''s clever little global container struct: #if !defined (GLOBALS_OWNERSHIP) extern #endif // !defined(GLOBALS_OWNERSHIP) struct { // ------------------ // Global Variables // ------------------ } Globals; So I put this in a file called Globals.h, which I have now included in all the source files in my project. But, I''m sad to say, this still hasn''t cured my problem. You see, I''m getting those cursed LNK2001 errors as so: Direct3D.obj : error LNK2001: unresolved external symbol "struct __unnamed Globals" (?Globals@@3U__unnamed@@A) Model.obj : error LNK2001: unresolved external symbol "struct __unnamed Globals" (?Globals@@3U__unnamed@@A) Main.obj : error LNK2001: unresolved external symbol "struct __unnamed Globals" (?Globals@@3U__unnamed@@A) Debug/InitDX8.exe : fatal error LNK1120: 1 unresolved externals I *have* defined GLOBALS_OWNERSHIP in my Main.cpp file, *before* the inclusion of Globals.h. Does anyone have ANY idea why this is still going wrong for me???? PLEASE help! Thanks, Gareth

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster

Doncha have to do sumpin like this:

extern Globals g;

????

Share this post


Link to post
Share on other sites
I don''t think so because the "Globals" thing is actually the instance of the structure itself. It''s an unnamed structure with the intention of having only one instance (or so I''m led to believe). Teej''s original code called this "G" instead of "Globals".

Thanks anyway!
Gareth

Share this post


Link to post
Share on other sites
You have #define GLOBALS_OWNERSHIP in at least on of the source-files, otherwise every source-file will have the globals-struct marked as extern.

-Neophyte

P.S. You must #define GLOBALS_OWNERSHIP *before* you include the globals.h in that source-file.

- Death awaits you all with nasty, big, pointy teeth. -

Share this post


Link to post
Share on other sites
Thanks, Neophyte, but I have already done that (it says towards the bottom of my original post). I''m going spare trying to solve this one!

Cheers,
Gareth

Share this post


Link to post
Share on other sites
Maybe check your spelling in your #defines

The only way that error will generate is if the ''extern'' is not removed from the structure declaration atleast once during compile. Which will only happen if GLOBALS_OWNERSHIP is not defined before you include that file. Unless maybe you are doing some other #ifndef or #ifdef tests in your globals.h and then including the globals.h inside of another include file which is then included before your #define GLOBALS_OWNERSHIP. A good rule is never include a global include file in another include file, always do it in your source files directly.

If you are using MSVC maybe try a full rebuild instead of incremental build. Sometimes fixes wierd linking errors.

Otherwise, post a simple example that you can''t get to work.

Seeya
Krippy

Share this post


Link to post
Share on other sites
Oops. Sorry for not reading your post properly...

Anyways, try changing the line
#if !defined (GLOBALS_OWNERSHIP)
to
#ifndef GLOBALS_OWNERSHIP

-Neophyte

- Death awaits you all with nasty, big, pointy teeth. -

Share this post


Link to post
Share on other sites

  • Advertisement