Jump to content
  • Advertisement
Sign in to follow this  
Ziel

Help! Linker error.

This topic is 2869 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

So in my program I have four .cpp files and a header file, Global.h, that includes all header files and function prototypes etc. I include Global.h in the four .cpp files, but I get an error saying some constructors are already defined. I don't get why because I use #ifndef #define tags in my header files. Here is the actual error:


1>------ Build started: Project: MTHPH, Configuration: Debug Win32 ------
1>Compiling...
1>Loop.cpp
1>Generating Code...
1>Compiling...
1>Display.cpp
1>FindAvgChance.cpp
1>FindHand.cpp
1>Generating Code...
1>Linking...
1>FindAvgChance.obj : error LNK2005: "public: __thiscall Card::Card(void)" (??0Card@@QAE@XZ) already defined in Display.obj
1>FindAvgChance.obj : error LNK2005: "public: __thiscall GameInfo::GameInfo(void)" (??0GameInfo@@QAE@XZ) already defined in Display.obj
1>FindHand.obj : error LNK2005: "public: __thiscall Card::Card(void)" (??0Card@@QAE@XZ) already defined in Display.obj
1>FindHand.obj : error LNK2005: "public: __thiscall GameInfo::GameInfo(void)" (??0GameInfo@@QAE@XZ) already defined in Display.obj
1>Loop.obj : error LNK2005: "public: __thiscall Card::Card(void)" (??0Card@@QAE@XZ) already defined in Display.obj
1>Loop.obj : error LNK2005: "public: __thiscall GameInfo::GameInfo(void)" (??0GameInfo@@QAE@XZ) already defined in Display.obj
1>C:\Users\~~~~\Documents\MTHPH\Debug\MTHPH.exe : fatal error LNK1169: one or more multiply defined symbols found


Help me please!!!

Share this post


Link to post
Share on other sites
Advertisement
By not submitting a short relevant code snippet, you give people even less information than you have, and you expect that at the same time they should be able to give a more informed analysis than you currently possess. Forum threads shouldn't be a game, let's not make it harder for no reason. ;)

Now, I'll go ahead and try the guessing game. I guess you did the inclusions correctly, and I guess the inclusion chains are ok. I guess that you do not have a file Card.cpp or GameInfo.cpp, and I guess you define non-inlined functions in the Global.h header file. That is, my guess is that your Global.h contains something like following:


#ifndef Global_h
#define Global_h

class Card
{
public:
Card();
};

Card::Card() // This should not be here. Either inline, move inside the class, or in a separate file Card.cpp (preferred).
{
}



Was that even close? If not, I'm sure that someone can give you a more helpful answer after you post a short snippet of the actual code.

Share this post


Link to post
Share on other sites
Yeah, your class function definitions are* in your .h file. Those must not be defined in multiple files and by including those they are being copied to each object (cpp) file.

This means you have a copy of the function in many files how would the linker know which one to use?


* Probably that is.

Share this post


Link to post
Share on other sites
Thanks for the help guys. I didn't mean to offend by leaving out info. I vaguely remember seeing this topic discussed awhile ago so I thought it was a common problem. I tried searching the forums first but didn't come up with anything. Anyway, once again, thanks.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!