3

For the purposes of troubleshooting an existing build (set of binary files, exe's, dll's, lib's).

Is there a way, with command line tools from SDK or other utility to quickly check the Runtime Library Type an object file was compiled against?

For example, given a .dll is obvious it was compiled against Dynamic runtime (but its still not obvious if it is the Debug or Release version).

While in the case of a .exe is more difficult (to determine eithr if Dynamic/Static and Debug/Release were used).

(I mean, without having to open the VC++ project files or looking at the compiler options used in a nmake / msbuild file).

1 Answers1

6

dumpbin /dependents will allow you to determine whether a module (EXE or DLL) depends on the Visual C++ libraries DLLs (and which versions and flavors--debug or release--of those DLLs). For example, with Visual C++ 2013...

When you compile with /MD, your module depends on the retail msvcr120.dll:

>cl /MD /nologo test.cpp
test.cpp

>dumpbin /dependents test.exe | findstr dll
    MSVCR120.dll
    KERNEL32.dll

When you compile with /MDd, your module depends on the debug msvcr120d.dll:

>cl /MDd /nologo test.cpp
test.cpp

>dumpbin /dependents test.exe | findstr dll
    MSVCR120D.dll
    KERNEL32.dll

When you compile with /MT or /MTd, your module does not depend on any CRT DLL:

>cl /MT /nologo test.cpp
test.cpp

>dumpbin /dependents test.exe | findstr dll
    KERNEL32.dll

>cl /MTd /nologo test.cpp
test.cpp

>dumpbin /dependents test.exe | findstr dll
    KERNEL32.dll

When you've statically linked the Visual C++ libraries, it's generally not possible to tell whether the retail or debug libraries were linked in (in general you can't tell whether any Visual C++ libraries were linked in). If you have a PDB for your module, you can often use that to figure out what was linked in, based on source file information and functions present in the module.

(Two notes: [1] My test.cpp file was a simple C Hello, World! program. If it linked other Visual C++ libraries dynamically, dumpbin /dependents will also report them. [2] dumpbin /dependents works equally well with DLLs.)

James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • `dumpbin` and `link` aren't distributable with Visual Studio (https://www.visualstudio.com/en-us/productinfo/2015-redistribution-vs) so it will have utility limited to the developer's end; How would I get similar queries via C or C++? I'm fine using OS libs to do it, but I need this kind of tool that I can distribute with some consuming modules. – kayleeFrye_onDeck Apr 27 '17 at 20:40