Hi, I'm a newbie to C++. I use Windows XP Home Edition and VC++ .NET 2003.
I have just recently started creating large scale C++ projects with more than one file. I've been having troubles linking the files together.
I solved the problem by adding "/FORCE:MULTIPLE" to the command line, but the compiler still gives linker warnings. I don't feel satisfied just by cheating my way out.
The real source files are large, and I know that it is a linker error, so I created smaller files with a similar structure that give the same errors.
Here are the source files:
stdafx.cpp
#include "stdafx.h"
Untitled.cpp
#include "stdafx.h"
#include "MyClass.cpp"
#include "OtherClass.cpp"
usingnamespace std;
int main()
{
myClass Class;
otherClass Class2;
return 0;
}
MyClass.cpp
#include "stdafx.h"
usingnamespace std;
class myClass
{
public:
myClass();
int variable;
void function1();
void function2();
};
myClass::myClass()
{
variable = 0;
}
void myClass::function1()
{
variable = 1;
}
void myClass::function2()
{
variable = 2;
}
OtherClass.cpp
#include "stdafx.h"
class otherClass
{
public:
otherClass();
int variable;
void function1();
void function2();
};
otherClass::otherClass()
{
variable = 0;
}
void otherClass::function1()
{
variable = 1;
}
void otherClass::function2()
{
variable = 2;
}
And here are the errors:
MyClass.obj : error LNK2005: "public: __thiscall myClass::myClass(void)" (??0myClass@@QAE@XZ) already defined in Untitled.obj
MyClass.obj : error LNK2005: "public: void __thiscall myClass::function1(void)" (?function1@myClass@@QAEXXZ) already defined in Untitled.obj
MyClass.obj : error LNK2005: "public: void __thiscall myClass::function2(void)" (?function2@myClass@@QAEXXZ) already defined in Untitled.obj
OtherClass.obj : error LNK2005: "public: __thiscall otherClass:0therClass(void)" (??0otherClass@@QAE@XZ) already defined in Untitled.obj
OtherClass.obj : error LNK2005: "public: void __thiscall otherClass::function1(void)" (?function1@otherClass@@QAEXXZ) already defined in Untitled.obj
OtherClass.obj : error LNK2005: "public: void __thiscall otherClass::function2(void)" (?function2@otherClass@@QAEXXZ) already defined in Untitled.obj
Debug/Untitled.exe : fatal error LNK1169: one or more multiply defined symbols found
Thanks in advance! :cheesy:
btw: Do error messages need "code" tags?