C++ – How to find the cause of this linker error

clibcmtdmsvcrtvisual c++

After going through a lengthy process to rename a project, my DLL project will not build in Debug mode (Release builds work):

MSVCRTD.lib(msvcr90d.dll) : error LNK2005: _CrtDbgReportW already defined in LIBCMTD.lib(dbgrpt.obj)

This project, and the five static libraries it depends on, are set to use "Multi-threaded Debug (/MTd)" (under C/C++|Code Generation|Runtime Library). I believe LIBCMTD.lib is the one for multi-threaded debug, but what is MSVCRTD.lib, and what could be causing this error?

If it makes a difference, this DLL is for Windows CE.

Best Answer

LIBCMT is what you need for /MT, MSVCRT is what you need for /MD. You are linking .obj and .lib files that were mixed, some compiled with /MT some with /MD. That's not good.

Usually it is the .lib files that cause the problem. Review their build settings and make sure their /M option is the same as your DLL project.

Also, beware of the trouble you can get into if the DLL was compiled with /MT. You'll have major problems when the DLL returns pointers to objects that the client needs to release. It can't, it doesn't use the same memory allocator.