How to check the runtime library type of a binary exe generated from VC++

。_饼干妹妹 提交于 2019-12-11 10:36:29

问题


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:


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.)



来源:https://stackoverflow.com/questions/28687620/how-to-check-the-runtime-library-type-of-a-binary-exe-generated-from-vc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!