Should I compile with /MD or /MT?

andy picture andy · Apr 16, 2009 · Viewed 86.9k times · Source

In Visual Studio, there's the compile flags /MD and /MT which let you choose which kind of C runtime library you want.

I understand the difference in implementation, but I'm still not sure which one to use. What are the pros/cons?

One advantage to /MD that I've heard, is that this allows someone to update the runtime, (like maybe patch a security problem) and my app will benefit from this update. Although to me, this almost seems like a non-feature: I don't want people changing my runtime without allowing me to test against the new version!

Some things I am curious about:

  • How would this affect build times? (presumably /MT is a little slower?)
  • What are the other implications?
  • Which one do most people use?

Answer

Mr Fooz picture Mr Fooz · Apr 16, 2009

By dynamically linking with /MD,

  • you are exposed to system updates (for good or ill),
  • your executable can be smaller (since it doesn't have the library embedded in it), and
  • I believe that at very least the code segment of a DLL is shared amongst all processes that are actively using it (reducing the total amount of RAM consumed).

I've also found that in practice, when working with statically-linked 3rd-party binary-only libraries that have been built with different runtime options, /MT in the main application tends to cause conflicts much more often than /MD (because you'll run into trouble if the C runtime is statically-linked multiple times, especially if they are different versions).