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
tool)?
Edit:
dumpbin /directives foo.lib
is a solution for the case where the lib
was not compiled with /GL
switch. Is there an option to inspect a lib
file that was optimized in such a way?
lib. /MT Creates a multithreaded executable file using LIBCMT. lib. /MTd Creates a debug multithreaded executable file using LIBCMTD. lib. Thus MT stands for Multithreaded and MD stands for Multithreaded DLL.
Markdown editing with Visual Studio Code.
A LIB file contains a library of information used by a specific program. It may store a variety of information, which may include functions and constants referenced by a program or actual objects, such as text clippings, images, or other media.
msvcrtd.lib. Static library for the Debug version of the native CRT startup for use with DLL UCRT and vcruntime. Not redistributable. /MDd.
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With