How can I resolve this link error in Visual Studio (LNK2005)?

Cute picture Cute · Jun 4, 2009 · Viewed 22.7k times · Source

I keep having linker errors of the following form:

libcmtd.dll msvmrtd.dll some element(ex: _mkdir ) already defined...

and I don't know how to resolve them.

Here is a complete error message:

private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)

MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)

Can you help me solve this issue?

Answer

rlbond picture rlbond · Jun 4, 2009

Check a few things:

  1. Are your header files guarded. I.e. do they have #ifndef guards.

  2. Are you defining (non-template) functions in headers without the inline keyword. That messes lots of stuff up.

  3. Are you trying to define templates in a .cpp file. All template definitions need to be in headers.

Post some code and exact error text please!