View Full Version : MSVC++ linking question

03-15-2002, 01:23 PM
Hi all

This is not an openGL question as such, more like a general coding question. But since there are so many smart people here, perhaps you can help me anyway http://www.opengl.org/discussion_boards/ubb/smile.gif. My problem is the following:

I am maiking a loader for the md3 format and have the following files:
main.h, main.cpp, md3.h and md3.cpp. Main.h includes md3.h. In md3.h I have declared a 3-dimensional array of floats like this: float n[256][256][0];
Now, when I execute the program it gives me a link error: MD3.obj : error LNK2005: "float (* n)[256][3]" (?n@@3PAY1BAA@2MA) already defined in main.obj

If I put the array in md3.cpp, there is no problem, but it is a bit of a hack, so... I'm supposing it has something to do with me including md3.h in main.h, but that seems to be a necescity, so what do I do? Should "global" variables be put in the cpp-files as a rule or what? I am not terribly good at, what should be included where, and any larger programs I write tend to cause such problems, so any insight you have, either general or on my specific problem would be greatly appreciated.

Regards Anders

03-15-2002, 01:45 PM
You can put your global variable in a .cpp and an extern in the corresponding .h


in md3.cpp:
in md3.h:
extern int GLOBAL_INT;

this way wherever you include md3.h you can access your global int