unresolved extern symbols - trying global for all files

Pages: 12
closed account (48T7M4Gy)
.
Last edited on
OMG!!

I just went back to my original code to see if I could find the culprit(s). I received only 5 error messages without making any changes. I resolved each error one by one, AND NOW THE CODE COMPILES WITHOUT ERRORS!!

What the hell? I was getting hundreds of error messages just 15 minutes ago, then it reduced to 5 errors without changes???

Even as strange, all the warning messages have disappeared. I had many type conversion warnings which are no longer showing.

I do not f'n get it.

At least it will now compile, and I can work on the runtime errors.
Last edited on
Sources are not transformed directly into an executable. Instead, `object files' are created from them (compilation) and then those object files are "merged" to create the executable (linking)
This reduces the building time, because if one source was not modified, then there is no reason to reanalyze it (recompile it)
you've got a lot of warnings, but it compiled. Now each time you try to build, it will not try to compile but just link. So you would not get the warnings.


Since a while you are being quite vague. You don't report on the errors messages that you get or the changes on your code.
I don't understand how do you expect to receive help like that.
Last edited on
To make a variable 'foo' available to all .cpp files:

1. DEFINE variable 'foo' in a foo.cpp file:

int foo = 3;

2. Create a header file 'foo_exports.h' that exports this variable:

extern int foo;

DON'T include 'foo_exports.h' in 'foo.cpp'

3. Include 'foo_exports.h' in any .cpp file where you want the 'foo' to be available.

4. (extra) If you wan't 'foo' to be available in a header file 'baz.h', you have to always include 'foo_exports.h' before 'baz.h'.
Last edited on
Also:

If 'foo' is not of type int, but of some other type 'Type':

1. Define 'Type' in foo.h:

struct Type
{
...
};

2. Include 'foo.h' in 'foo.cpp'

3. Always include 'foo.h' before 'foo_exports.h'
- OR-
include 'foo.h' in 'foo_exports.h', but in this case you have to be carefull not to include 'foo.h' twice (for example, by including both foo.h and foo_exports.h in the same .cpp file
Or, there is this easier solution:

Create foo in foo.cpp:

int foo = 8;
- OR -
Type foo;

After this, add a function to foo.cpp which returns reference to foo:

int& Foo() { return foo; }
-OR-
Type& Foo() { return foo; }

in foo.h file, declare function Foo:
int& Foo();
-OR-
Type& Foo();

Now , whereever you include foo.h, you can access foo through Foo() function.



ne555:
As I mentioned in the post just before yours, there were no changes and the code compiled with only 5 errors which I resolved. Then it was compiling an executable.

This is the dominate error: error LNK2001: unresolved external symbol
Which had gone away without me making changes.

keymort:
Then explain why the compiler gives me different error messages without me making changes... and then suddenly only had 5 errors (instead of hundreds) without me, again, making changes.

All I did was exit the compiler and then reopen it. When I resolved the 5 errors, I was able to generate an executable.

Since then I have compiled the code several times as I am trying to find out why one of my variables is incrementing in the main loop. Still have not found anywhere in the code that is adding to or incrementing that variable.

Then on my most recent build, I get the same unresolved extern symbol errors as from my original post. Again, I have changed nothing, merely looking through the code and doing searches. No changes, and yet the compiler is giving the same errors as I had originally before the errors went away.

So, no, the mirror is not showing me the problem.
Last edited on
Is now an appropriate time to mention that global variables are usually a really bad idea, and will probably end up causing more problems than they'll solve? And that you should really think about redesigning your code so that it doesn't use them?
Topic archived. No new replies allowed.
Pages: 12