athos athos - 3 months ago 11
C++ Question

Visual Studio C++: will using /MT causes run-time library be linked in multiple times?

I understand that

/MT
compiler option causes the application to use the multithread, static version of the run-time library.

Suppose my solution consists main project
PrjMain
as a Win32 console application, and a
PrjLib
compiled as static library, both using
\MT
. Will the CRT be linked into the final
PrjMain.exe
twice -- once by the
PrjMain
, once via
PrjLib
as a static libary?

Answer

The CRT will only be linked in once. Both the main project and the PrjLib library will link to the same static CRT, as long as both the project and library are compiled into one binary.

Where problems come from are when mixing a module that uses a static CRT with one that uses the DLL CRT in one binary, or when using multiple binaries (an executable and a DLL) that both use the static library. In those cases you'll get two copies of the CRT loaded, which can cause problems.