我应该用/MD 还是/MT 编译? [英] Should I compile with /MD or /MT?

查看:43
本文介绍了我应该用/MD 还是/MT 编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 中,有编译标志/MD 和/MT,可让您选择所需的 C 运行时库类型.

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?

我听说/MD 的一个优点是它允许某人更新运行时(例如可能修补安全问题)并且我的应用程序将从此更新中受益.尽管对我来说,这几乎像是一个非功能:我不希望人们在不让我针对新版本进行测试的情况下更改我的运行时!

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!

一些我很好奇的事情:

  • 这将如何影响构建时间?(大概/MT 会慢一点?)
  • 其他含义是什么?
  • 大多数人使用哪个?

推荐答案

通过与/MD 动态链接,

By dynamically linking with /MD,

  • 您会接触到系统更新(无论好坏),
  • 您的可执行文件可以更小(因为它没有嵌入库),并且
  • 我相信至少 DLL 的代码段在所有积极使用它的进程之间共享(减少消耗的 RAM 总量).

我还发现,在实践中,当使用使用不同运行时选项构建的静态链接的第 3 方仅二进制库时,主应用程序中的/MT 往往比/MD 更容易引起冲突(因为如果 C 运行时被多次静态链接,你会遇到麻烦,尤其是当它们是不同的版本时).

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).

这篇关于我应该用/MD 还是/MT 编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆