standard library already defined in lib, causing linker error
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.
Related videos on Youtube
meds
Updated on June 04, 2022Comments
-
meds almost 2 years
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?
-
sligocki over 12 yearsCan you include the entire source of all the functions you are using and the command line then?
-
meds over 12 years"with the Runtime library option: Multi-threaded (/MT) and the test project with the option: Multi-threaded DLL (/MD) for example." bingo, that was exactly it (came here to post that)
-
John Dyer almost 11 yearsThis other question is related: stackoverflow.com/questions/4917592/…
-
zezba9000 over 10 yearsMan sometimes C++ error messages blow my mind at how ambiguous they are. This is why I use C# for my main code base and C++ for components only.
-
user1122069 about 7 years@ksming I have these settings and the error. But how do I change them in the Visual Studio GUI?