問題描述
在 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 編譯?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!