globals are evil.
globals in header files are especially evil.
You're getting these errors because you have a global in a header file, and that header file is included in multiple cpp files. Since #include is basically a copy/paste operation, this means that
each source file is defining its own variables with those names. Then the linker gets confused because it has all these duplicate variable names and it doesn't know which one to use.
The solution here is to
not use globals (or at least avoid them). Heavy use of globals is a tell tale sign of terrible design.
If you must use globals, you can get around the problem with the extern keyword:
1 2 3 4 5
|
extern int foo; // tells the compiler that a variable named foo exists somewhere
// without actually generating a variable
// vs.
int foo; // tells the compiler that the variable exists AND generates that variable.
|
In practice, you would put the non-extern var in
one and only one cpp file, and the extern in a header:
1 2
|
// globals.h
extern int myglobal;
|
1 2 3
|
// globals.cpp
int myglobal;
|
But this makes it so you have to duplicate all the variable declarations (one in the header and again in the cpp, and both must match). To avoid that, you can use #define magic to cheat:
1 2 3 4 5 6
|
// globals.h
#ifndef GLOBAL
#define GLOBAL extern
#endif
GLOBAL int myglobal;
|
1 2 3
|
//globals.cpp
#define GLOBAL
#include "globals.h"
|
1 2
|
//all_other_cpp_files.cpp
#include "globals.h"
|
EDIT:
That will solve your first 3 erorrs anyway. As for the last 2:
1>Input.obj : error LNK2001: unresolved external symbol "struct tagPOINT MousePos" (?MousePos@@3UtagPOINT@@A)
This is telling you that you didn't define your MousePos struct. Either that or you're not linking to the cpp file that defines it.
1 2
|
1>Render.obj : error LNK2019: unresolved external symbol "void __cdecl RenderMainMenuPlayNotSelected(void)" (?RenderMainMenuPlayNotSelected@@YAXXZ)
referenced in function "void __cdecl Render_Frame(int)" (?Render_Frame@@YAXH@Z)
|
Similarly, this is telling you that you didn't give your RenderMainMenuPlayNotSelected function a body. That or you didn't link to the file that contains the body.