views:

110

answers:

2

I am building a project in Visual C++ 2008, which is an example MFC-based app for a static C++ class library I will be using in my own project soon. While building the Debug configuration, I get the following:

warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

After using the recommended option (by adding "msvcrt" to the "Ignore specific library" field in the project linker settings for the Debug configuration), the program links and runs fine. However, I'd like to find out why this conflict occured, why do I have to ignore a critical library, and if I'm to expect problems later I if add the ignore, or what happens if I don't (because the program builds anyway).

At the same time, the Release configuration warns:

warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification
warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

I'm guessing that the "D" suffix means this is the debug version of the vc++ runtime, no idea why this gets used this time. Anyway, adding "msvcrtd" to the ignore field causes lots of link errors of the form:

error LNK2001: unresolved external symbol imp_CrtDbgReportW

Any insight greatly appreciated.

A: 

This usually happened to me when I was (inadvertently) mixing different flavours of the RTL, like (as it seems to be in your case) Debug and Release or MT and ST.

sbi
Both configurations use the "Multi-threaded DLL (/MD)" variant of the runtime. Or did you mean something else?
neuviemeporte
@neuviemeporte: See sharptooth's answer for how this could still happen.
sbi
+1  A: 

This usually happens when you link against a static library that uses another version of the VC++ runtime (C++ ->Code Generation->Runtime Library setting in the project properties).

sharptooth
I selected /MDd in both configurations and the warnings are gone, guess the library was built with the debug version of the RT. Still wondering why MSVCRT ended up as the default for the Debug build, and MSVCRTD for the Release. Seems to me the default should be MSVCRTD for both?
neuviemeporte
Perhaps that's a fault of the library developers. Debug should be only used for debug builds - it is significantly slower.
sharptooth