I use CMake with CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS to automatically generate both a shared dll and static .lib library on Windows when building with MSVC. I found out yesterday that the static .lib uses dynamic linking and hence requires using the /MD compiler option (instead of /MT). This is a bit surprising to me, why does it not use static linking for static .lib files?
MSVC_RUNTIME_LIBRARY: “If this property is not set then CMake uses the default value MultiThreaded$<$<CONFIG:Debug>:Debug>DLL to select a MSVC runtime library.”
What is the reason for using MultiThreadedDLL by default (instead of MultiThreaded) for static .lib files? Maybe that is a good choice and I just fail to understand…
Because you cannot mix them well. Compiling every static library with the static runtime is problematic when linking static and dynamic libraries into an executable.
Yes, I know. But in my project I have renamed that file to .dll.lib and I also generate a true static .lib library. And this static .lib is linked using /MD by default. (Which is totally fine, I just wanted to understand why /MD is used instead of /MT)