Sign in to follow this  
Jarwulf

linker errors

Recommended Posts

I'm getting a ton of linker errors for C++ VS2008 like these
MenuStateS.obj : error LNK2005: "int (* raycastclose)[2]" (?raycastclose@@3PAY01HA) already defined in main11.obj
1>MenuStateS.obj : error LNK2005: "int (* raycast)[2]" (?raycast@@3PAY01HA) already defined in main11.obj
1>MenuStateS.obj : error LNK2005: "void __cdecl collisioneffectdamage(class sf::Sprite &,float,float,float,float,float,float,float,float,int &,int &)" (?collisioneffectdamage@@YAXAAVSprite@sf@@MMMMMMMMAAH1@Z) already defined in main11.obj
1>MenuStateS.obj : error LNK2005: "void __cdecl collisioneffectpushback(class sf::Sprite &,float,float,float,float,float,float,float,float)" (?collisioneffectpushback@@YAXAAVSprite@sf@@MMMMMMMM@Z) already defined in main11.obj
1>MenuStateS.obj : error LNK2005: "void __cdecl DealExplosion(class sftools::Animated &)" (?DealExplosion@@YAXAAVAnimated@sftools@@@Z) already defined in main11.obj
I think it might be something like a file or library included twice or a similar problem. What sort of things usually cause these type of errors?

Share this post


Link to post
Share on other sites
It sounds like you have non-extern global variable definitions and non-inline function definitions in one or more of your header files. To fix, make sure that only extern declarations for global variables are in the header and that they are defined properly in a source file and that any functions defined in headers are explicitly or implicitly inlined. More details.

Share this post


Link to post
Share on other sites
I seem to remember getting those when I define functions in the header files.
In general you should only have declarations in your header files and keep the definitions in source files.


In addition to that you might want to make sure you use inclusion guards in all your header files

#define SOME_QNIQUE_LABEL

Declarations here...

#endif


edit:
SiCrane beat me to it, and explained to better as well

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this