#ifndef _XGLOBALS_H_
#define _XGLOBALS_H_
#include "Impulse.h"
HWND MainWindowHandle;
HINSTANCE MainWindowInstance;
#endif
Header Linking Problem
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.
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.
extern HWND MainWindowHandle;
in the header and
HWND MainWindowHandle;
in one source file.
For more details see this article.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement