Visual Studio Runtimes

Most libraries (both static and dynamic) link with the C-runtime. At link-time, all of the dependent libraries (sdk's) need to reference the same runtime, or else you can run into obscure and difficult to debug problems. Visual Studio comes with multiple versions of thestandard library. You can select it under "Properties", "Configuration Properties", "C/C++ code generation", "Runtime Library".

below a screenshot showing the dialog in Visual Studio 2010:


 Basically you have the following options:

switchnamestatic or dynamicdebugLinked with.vcxproj <RuntimeLibrary>
/MT Multi-threaded Static (runtime linked statically into exe/lib) No LIBCMT.lib MultiThreaded
/MTd Multi-threaded Debug Static (runtiime linked statically into exe/lib) Yes LIBCMTD.lib  
/MD Multi-threaded DLL Dynamic (load runtime from msvcrt*.dll) No MSVCRT.lib  
/MDd Multi-threaded Debug DLL Dynamic (load runtime from msvcrt*.dll) Yes MSVCRTD.lib  


LNK4098: defaultlib "LIBCD" conflicts with use of other libs

Now when one or more of your libraries are linked with a different runtime, the linker will issue a warning: 

"LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs; use /NODEFAULTLIB:library".

Now you can follow the compiler suggestion and blissfully ignore it - which is the worst way to 'solve' it. To do this, open your project properties, select "linker", "general" and enter the library you want to exclude, for example "libcmt.lib". Alternatively enter /NODEFAULT:lib  in the linker commandline options.

The better alternative is to figure out what the offending library is which is using a different runtime. The most common one used is /MD(d). To determine this you have several approaches. 

First off, you should know which libraries you are actually linking with. 

You can look at the linker-settings to see this. 

<todo: linker-settings screenshot>

Besides these, you should search the code for #pragma comment(lib, "xxx.lib") as these libraries will also be linked into your library/executable.

You can also let the linker tell you which libraries it wants to link. Under "linker" change the "Show Progress" to "/VERBOSE:LIB" and do a (re)build of your solution - then it will show you a list of libraries.


Determining offending library

Now to figure out which ones is compiled with the wrong runtime you have several options:

1. Manually open the solutions for your libraries and check the compiler settings

2. Use a "find in files" in *.vcxproj and look for "<RuntimeLibrary>MultiThreaded</RuntimeLibrary>" (for /MT this xml-node will contain "MultiThreaded").

3. Use dumpbin (installed with the visual studio tools) on each library to figure out which runtime it requires. 

<todo: example batch>

Note that for some lib's it doesn't show which runtime they are linked with!

<todo: example output of dumpbin, example of when it doesn't work>


Once you figure out the offending library, you will need to set it to the correct runtime and rebuild it from sourcecode. After that, this warning will go away.


JSN Teki template designed by