#### Archived

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

# MSVC++ 6 Errors...

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

## Recommended Posts

Yes it does. Don't instantiate a var in any header files. Declare it with a

extern int TestVar;

in the header, and then instantiate it in ONE of the test.cpp files (there should be a .cpp file that 'goes along' with the header).

int TestVar = 1;

This is standard C, not related to VC specifically.

Rock

##### Share on other sites
Thank you, that fixed half of my problems! The other half of them pertains to DirectX problems. Here's the scenario, I have Test1.h, Test1.h includes "dxfunctions.h", which is a bunch of dx functions that I made. "dxfunctions.h" includes "ddraw.h" and "dinput.h". I compile the code and I get tons of errors (Tons of variables in ddraw.h), that have the general form of this...

test1.obj : error LNK2005: _GUID_CustomForce already defined in dxfunctions.obj

Thanks for your previous reply Rock, anyone got any fixes for this now?

##### Share on other sites
I had a similar problem a long time ago.
I solved it by doing this:

code:
// Test1.h#ifndef _TEST1_H_INCLUDED#define _TEST1_H_INCLUDED// your code#endif

Maybe this helps.

##### Share on other sites
Melo's idea is good, and should be used in all header files, but it doesn't sound like that's the problem (I may be wrong). It still sounds like you've defined something in dxfunctions.h, and its being compiled into both dxfunctions.obj and test1.obj. I'd check again, or post the header file.

Rock

##### Share on other sites
Well, inside of "dxfunctions.h", I include "ddraw.h", "dinput.h" and "ddutil.h"... Should I include these files in the .cpp file instead? Also, if you look at the example in my first post, I use the #ifndef LALALA, #define LALALA, #endif thing, so that can't be the problem, however thanks for your input none the less....

##### Share on other sites
Make sure you have #define INITGUID in your main c/c++ file. Also include dxguid.lib in your linker settings.

##### Share on other sites
Haha. Sorry, I didn't double check your original post. Keep up the #if/#define stuff.

Anyways, you should be able to include the dx headers in your own headers without trouble. Without seeing your file, I couldn't say what the problem is. You aren't instatiating the var in both the cpp files, right? However its being done, the var is getting compiled into both the obj files, hence the 'already defined' error. The only ways that it could happen is that it is instantiated in a header file, and thereby a copy is defined in every obj file that includes that header (my 1st reply). Or you have manually instantiated the var in multiple cpp files.

Rock

##### Share on other sites
Well, it dosn't seem to be (directly) my fault anymore. In the source I have, I havn't declared any variables IN my source, ALL the error messages have to do with DirectDraw...

I'm looking at some of the examples that came with the SDK, and they're headers seem to use variable names like "LPDIRECTDRAW7" WITHOUT calling the header first, how is this possible!?

##### Share on other sites
This is because custom header files are generally included AFTER standard headers. So ddraw.h should be included first (in the cpp file), then the custom header which uses LPDIRECTDRAW7 is included. Since ddraw.h is already included, it works without a problem.

Good luck

Starfall

##### Share on other sites
Any of you MSVC veterans out there (I'm new to MSVC) know what's wrong with the following code? (Thanks in advance)

------

int TestVar = 1;

#endif

test1.cpp
---------
// yup, just one line

test2.cpp
---------
// Appropriate standard includes here...

main()
{
cout << TestVar << endl;
getch();
}

Well, that's a summary of the code, here's the error I get...

test2.obj : error LNK2005: "int TestVar" (?TestVar@@3HA) already defined in test1.obj

I guesse it has something to do with globally defined variables in header files that are include in more than one other file. Well, any help would be nice, as I'd like to get this code working soon, thanks!

Vore

• ### Forum Statistics

• Total Topics
628696
• Total Posts
2984267

• 19
• 9
• 13
• 13
• 11