Jump to content
  • Advertisement
Sign in to follow this  
egg100

C++ linking

This topic is 4882 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've had this error for 2 days now I'm about to lose the plot! error LNK2005: "struct IDirectInputDevice8A * InputDevice" already defined in... and error LNK2005: "struct IDirect3DDevice9 * Device" already defined in... The way my include headers are structured is that d3dx9.h & dinput.h have to be included twice when linking, but I thought the #ifndef statement should mean this wont be a problem? I've really run out of ideas ????? Any ideas would be much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Did you define InputDevice and Device in your header files ? You only have to declare them, then define them in a source file.

Example:

// Device.h
#ifndef DEVICE_H
#define DEVICE_H

...

// declare the pointer
extern struct IDirectInputDevice8A* InputDevice;

...

#endif

// Device.cpp
#include "Device.h"

// define the pointer
struct IDirectInputDevice8A* InputDevice;




Edit:
You may also want to read here
http://www.gamedev.net/reference/articles/article1798.asp

Share this post


Link to post
Share on other sites
Do not define variables in header files. If you do, each translation unit that includes that header generates a copy of the variable. The linker then sees all those identically-named symbols and tells you it can't do anything with that. it Iis not the linker's job to resolve such conflicts.

Declare the variable in the header file, define it in a (single) source file.

Share this post


Link to post
Share on other sites
Wow. Thank XXXX for that.
I had defined some variables in the header file. I've moved them to a source file and it seems to work fine.
Thanks a lot guys.


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!