Analyzing linker errors

posted Jul 8, 2014, 1:48 AM by Nico Kruithof

Sometimes you get a linker error that two different kinds of c runtime libraries are used (msvcrt.lib and libcmt.lib). This means that part of the code is compiled with /MD and another part with /MT (or their debug variants). The following helps analyzing the problem as visual studio is not very verbose.

To analyze the library dependencies in the *.obj files, you can runthe following command via the Visual Studio command prompt (in the temp folder of the project, where *.obj files are generated):

for /R %1 in (*.obj) do @dumpbin /directives /section:.drectve %1 > %1.directives.txt

With Notepad++ you can then to search for the name of the offending library in all of these *.directives.txt files. This revealed which project was referencing the wrong lib.

Note: you may want to modify this to include any 3rd-party *.lib files your project may use, and not just *.obj files. "/DEFAULTLIB" directives may also come from them.

for /R %1 in (*.lib) do @dumpbin /directives /section:.drectve %1 > %1.directives.txt