I'm trying to port a project to VS2005 beta2 and I get lots of errors like this.
libcmtd.lib(sprintf.obj) : error LNK2005: _sprintf already defined in msvcrtd.lib(MSVCR80D.dll)
libcmtd.lib(swprintf.obj) : error LNK2005: __swprintf already defined in msvcrtd.lib(MSVCR80D.dll)
libcmtd.lib(dbgheap.obj) : error LNK2005: _malloc already defined in msvcrtd.lib(MSVCR80D.dll)
libcmtd.lib(dbgheap.obj) : error LNK2005: _free already defined in msvcrtd.lib(MSVCR80D.dll)
Can anyone point me in the direction of fixing this?
If its related to project properties can you specify which ones would cause it.
Today I also had this problem.
It was solved by setting the "Configuration Properties" / "C/C++" / "Code Generation" / "Runtime Library" property to "Multi-threaded Debug (/MTd)".
(The previous value of this property was "Multi-threaded Debug DLL (/MTd)".)
Maybe this can help to others as well.
Similar problems have occurred many time in my projects. If you have to use the library libcmtd.lib and you cannot fix the error in any other way, you can just add "/FORCE:MULTIPLE" to the linker command line in your project property.
However, note that, this linker selection won't work correctly every time. It may incur unexpected runtime performance, since it will just choose the first implementation of the function and desert another, though it always work well in my projects.
- Proposed as answer by Zdenek Gardelka Monday, September 01, 2008 8:42 AM
Using /FORCE:MULTIPLE and /NODEFAULTLIB is almost always a bad idea. It may work for some of the most simple cases, but will fail in much worse ways for the vast majority of real-world programs.
The real solution is to make sure you use the same compiler toolchain with compatible settings for all contributing object files including such contained in static libraries.
Visual C++ Libraries Team