Hi, I'm having some issues probably because of my lack of experience but I can't see it through. This code has to be with OpenGL and I'm using Visual Visual C++ 2010
I have 2 cpp files A and B, and A has a header file, C included in A and B.
A is just some base code so I can programm and change B at my will. And I had to declare some variables that A and B could read so I declared them at C.
I have preprocessor directives so the structs, functions and vars at C aren't declared twice:
#ifndef GL_FRAMEWORK__INCLUDED
#define GL_FRAMEWORK__INCLUDED
But I'm always having issues with already defined vars (not structs or functions) when linking B
What is the contents of that header? If a header contains something that can't be defined multiple times (like non-inlined functions) and you include it in multiple files, the linker will not be too happy with you.
And I had to declare some variables that A and B could read so I declared them at C
If you define objects within a header module, you're asking for the multiple definition error. When a header module is included into another header module, the header that included the other obtains a copy of all the objects defined within that header module. For example:
Header_A.h
1 2 3 4 5 6
#ifndef _H_A_
#define _H_A_
int Object( 0 );
#endif
Header_B.h
1 2 3 4 5 6
#ifndef _H_B_
#define _H_B_
int Object( 0 );
#endif
Header_C.h
1 2 3 4 5 6 7 8 9 10 11
#ifndef _H_C_
#define _H_C_
#include "Header_A.h"
#include "Header_B.h"
// Including both A, and B modules will result in this:
int Object( 0 ); // Front Header_A.hint Object( 0 ); // Front Header_B.h
#endif
Since you are using VS 2010 check out __declspec(selectany), you use it as a prefix to any variables in h-files (that will be included in more than 1 source file) and the VS linker only chooses one of them.