Header Linking Problem

Started by
1 comment, last by cptrnet 18 years, 8 months ago
I added this code to my project, my main header to include is Impulse.h before I added this code it worked fine, now I try to run it says that these are already defined. I have checked all my headers to make sure they have the #ifndef #define structure. I looked back at some other code I wrote and I did this also and that doesn't give me link errors. I have commented out thousands of lines of code to get to the bottom of it, but no luck. I have no idea whats going on. If anyone would like to look at all my code I will zip it but I don't have any web space so you can't download it, but I guess I can email it to you. thanks.

#ifndef _XGLOBALS_H_
#define _XGLOBALS_H_

#include "Impulse.h"

HWND	  MainWindowHandle;
HINSTANCE MainWindowInstance;

#endif

If you insist on saying "DUH", try to make a post that makes a little more sense
Advertisement
When you define non-const global variables in headers, you should declare them with the extern keyword. Then in one source file, at namespace level (not inside a function or a class), define the variable without the extern keyword. In your example you would have
extern HWND MainWindowHandle;
in the header and
HWND MainWindowHandle;
in one source file.

For more details see this article.
Thank you so much, I have been going crazy over this the past couple of days. Thanks again.
If you insist on saying "DUH", try to make a post that makes a little more sense

This topic is closed to new replies.

Advertisement