Link problems with static library

Link problems with static library

An application is generating the following errors:

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in libcmtd.lib(dbgmalloc.obj)
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in libcmtd.lib(dbgfree.obj)
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __endthreadex already defined in libcmtd.lib(threadex.obj)
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __beginthreadex already defined in libcmtd.lib(threadex.obj)
1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fprintf already defined in libcmtd.lib(fprintf.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>.\Debug/MyApp.exe : fatal error LNK1169: one or more multiply defined symbols found

Q148652 explains the problem and ways to solve it.

I found that I was linking a static library that was compiled with the C/C++…Code Generation…Runtime Library option set to Multi-threaded Debug DLL (/MDd).

My application was using Multi-threaded Debug (/MTd).

The problem went away once I created a version of the static library that was compiled using Multi-threaded Debug (/Mtd) to match the application.

Leave a Reply