Should I compile with /MD or /MT?

2019-01-03 20:51发布

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?

7条回答
Deceive 欺骗
2楼-- · 2019-01-03 21:54

I prefer to link statically with /MT.

Even though you do get a smaller executable with /MD, you still have to ship a bunch of DLLs to make sure the user gets the right version for running your program. And in the end your installer is going to be BIGGER than when linking with /MT.

What's even worse, if you choose to put your runtime libraries in the windows directory, sooner or later the user is going to install a new application with different libraries and, with any bad luck, break your application.

查看更多
登录 后发表回答