Reputation: 22926
Not sure what I'm doing wrong here, but say I have:
foo.h
class foo
{
public:
int Get10(std::wstring);
};
foo.cpp
int foo::Get10(std::wstring dir)
{
return 10;
};
And I compile it as a lib, if I include that lib in another project along with the relevant header (foo.h) and atttempt to call an instance of foo:
foo f;
f.Get10(L"ABC");
I get a linker error saying:
Error 1 error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12@std@@QAE@XZ) already defined in foo.lib(foo.obj) C:\foo\msvcprtd.lib(MSVCP100D.dll) footest
Any ideas why this happens?
Upvotes: 10
Views: 19246
Reputation: 1462
Error 1 error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12@std@@QAE@XZ) already defined in foo.lib(foo.obj) C:\foo\msvcprtd.lib(MSVCP100D.dll) footest
From what I can see, this error message means that you are trying to include MSVC runtime library twice. This could be due to the result of compiling the foo.lib
with the Runtime library option: "Multi-threaded (/MT)" and the test project with the option: "Multi-threaded DLL (/MD)" for example.
Check the Runtime options under "Project Properties" ==> "C/C++" ==> "Code Generation" for both projects and make sure they are the same for both projects.
Upvotes: 28
Reputation: 6387
Are you including foo.h in any .h files? You may need to add header guards to make sure you do not define the class more than once per file:
#ifndef FOO_H_
#define FOO_H_
class foo
{
public:
int Get10(std::wstring);
}
#endif // FOO_H_
See also: http://en.wikipedia.org/wiki/Include_guard
Upvotes: 0