How to tell if a lib was compiled with /mt or /md?

前端 未结 2 1711
轮回少年
轮回少年 2020-12-08 04:50

Given a compiled lib, is there a way to tell if it was compiled with /md or /mt just by looking at it (maybe with dumpbin

相关标签:
2条回答
  • 2020-12-08 05:34

    Yes, you could use dumpbin's /DIRECTIVES option to find which runtime libraries the objects in the .lib want to link with:

    dumpbin /directives foo.lib
    

    Look for instances of the runtime libraries specified here. For example, you might see:

    /DEFAULTLIB:MSVCRTD (module compiled with /MDd)

    or

    /DEFAULTLIB:MSVCRT (module compiled with /MD)

    or

    /DEFAULTLIB:LIBCMT (module compiled with /MT)

    There will probably be many /DEFAULTLIB directives, so you can search using terms like:

    dumpbin /DIRECTIVES foo.lib | find /i "msvcr"
    

    Hope this gets you on the right track.

    0 讨论(0)
  • 2020-12-08 05:37

    A very nice feature of the Microsoft compiler is that it preserves the command line that was used to compile a source file into the .obj file. Which allows you to find it back by looking at the .lib file with, wait for it, Notepad.exe. Just search for "cl.exe".

    For example, this is what I see when I use Notepad opened on a sample library named Win32Project1.lib that I built with VS2013:

    C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe cmd -c -ZI -nologo -W3 -WX- -sdl -Od -Oy- -DWIN32 -D_DEBUG -D_LIB -DHELLO_STACKOVERFLOW -D_UNICODE -DUNICODE -Gm -EHs -EHc -RTC1 -MDd -GS -fp:precise -Zc:wchar_t -Zc:forScope -Ycstdafx.h -Fp"c:\Users\hpass_000\documents\visual studio 2013\Projects\Win32Project1\Debug\Win32Project1.pch" -Fo"c:\Users\hpass_000\documents\visual studio 2013\Projects\Win32Project1\Debug\" -Fd"c:\Users\hpass_000\documents\visual studio 2013\Projects\Win32Project1\Debug\vc120.pdb" -Gd -TP -analyze- -errorreport:prompt -I"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" -I"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\um" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\shared" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\winrt" -X src stdafx.cpp pdb c:\Users\hpass_000\documents\visual studio 2013\Projects\Win32Project1\Debug\vc120.pdb

    As you can tell, I compiled with /MDd

    Do beware that a .lib can contain multiple .obj files with possibly different settings. Searching for "-mt" and "-md" lets you find out quickly.

    0 讨论(0)
提交回复
热议问题