error LNK2005 - already defined

hello,

I know this error has been published many times but I couldn't find a solution to mine.

I have 4 files:
def.h
mms.h
mms.cpp
runMms.cpp

In the first one I define a struct. In the second I declare/create a new class called mms and I include "def.h". The third one is the cpp file of the class and I include in it "mms.h" (no, I don't include in it "def.h"). The fourth and last has the 'main' and I include in it "mms.h"

For some reason I'm getting the "error: lnk2005 alread defined ..." I know it usually has to do with putting some header file or definitions twice but I can't see where I got wrong.

I would appreciate it if any helprs could attached a code sample or something like that.

Thanks.
ilanhak wrote:
The fourth [...] I include in it "mms.h"
The fourth one is a source .cpp file - you had better not be writing #include "anything.cpp" ever.
As LB said, do not include other source files.

Another problem might be that you have a function body fully defined in a header (which will be a problem unless the function is a template or is inlined).

Or.. another problem might be that you have a variable declared in a header.

It's impossible to be more specific without actually seeing the error message in full. The error message will actually tell you exactly what symbol is being multiply defined... so it helps to read/post it.
I know it usually has to do with putting some header file or definitions twice but I can't see where I got wrong.



I hope you use include guards in header files (or #pragma once as you are using Visual Studio)
The problem was with inline declartions of struct data members in "def.h".

Thanks....
Are you using #ifndef, #define, & #endif?? If not, it could be redefining it.
Topic archived. No new replies allowed.