Advertisement Jump to content
Sign in to follow this  

Header Linking Problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;


Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!