Skip to main content
gamedev.net
🔒 Locked

LNK2005

Started by Sfpiano Jan 15, 2005 at 3:19 PM 1 replies 550+ views
Original Post
Sfpiano
Sfpiano
I have a .h file that contains a bunch of functions. I include this file in multiple other files so that they can use the functons, but when I do, I get error like: bool EqFloat3(float t1, float t2, float t3)LNK2005: "bool __cdecl EqFloat2(float,float)" already defined in CCube.obj for every function in the .h file. I am #ifndef...#def... so that's not the problem.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
daerid
daerid
If the actual function body is defined the the .h file, you will need to declare it as inline, or else that error will result.
daerid@gmail.com
HarryW
HarryW
Define the function bodies in a .cpp file, and only put the function prototypes in the .h file. #ifdefs will just mean that the code in your header will only get parsed once per translation unit (which is all the code that's parsed when you compile a .cpp), but if you have several .cpps then you'll have the functions defined in multiple object files. When the linker links them together, it will find multiple definitions and that's the error you're getting.
Harry.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.