Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

Header Linking Problem

This topic is 4855 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;

#endif

Share this post


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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!