visual-studio 为什么 /clr 与 Visual Studio 中的 /mt 和 /mtd 不兼容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/938539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:35:54  来源:igfitidea点击:

Why is /clr incompatible with /mt and /mtd in Visual Studio?

visual-studiovisual-c++visual-studio-2005c++-cliconditional-compilation

提问by Cute

can anybody please explain for me how and why /clr is incompatible with /mtd ? What is the alternative for this? What happens internally if I use /md or /mdd ?

有人可以为我解释一下 /clr 与 /mtd 不兼容的方式和原因吗?什么是替代方案?如果我使用 /md 或 /mdd 在内部会发生什么?

As far as I know we don't combinedly use /clr and /mtd. Can someone explain if there is a way to do this? And please explain me how and why /clr is incompatible with /mt and /mtd in Visual Studio?

据我所知,我们没有结合使用 /clr 和 /mtd。有人可以解释一下是否有办法做到这一点?请解释一下 /clr 如何以及为什么与 Visual Studio 中的 /mt 和 /mtd 不兼容?

采纳答案by 1800 INFORMATION

I expect the clue is given here:

我希望这里给出线索:

If you are using the /clr compiler switch, your code will be linked with an import library, msvcmrt.lib. The import library references a new library, msvcm80.dll, which provides a proxy between your managed code and the native CRT. You cannot use the statically linked CRT ( /MT or /MTd options) with /clr. Use the dynamically-linked libraries (/MD or /MDd) instead.

如果您使用 /clr 编译器开关,您的代码将与导入库 msvcmrt.lib 链接。导入库引用了一个新库 msvcm80.dll,它提供了托管代码和本机 CRT 之间的代理。不能将静态链接的 CRT(/MT 或 /MTd 选项)与 /clr 一起使用。请改用动态链接库(/MD 或 /MDd)。

The /clr flag causes your code to reference a new dll msvcm80.dll - this acts as a proxy between your managed code and the CRT. It's difficult to say exactly what this proxy does, but I guess it acts as an interface for allocations on the managed heap, garbage collection, managed threads and that kind of thing. If you link the static versions of the CRT, then the proxy would not be able to intercept your calls to the runtime libraries.

/clr 标志使您的代码引用新的 dll msvcm80.dll - 它充当托管代码和 CRT 之间的代理。很难确切地说这个代理做了什么,但我猜它充当了托管堆上的分配、垃圾收集、托管线程等等的接口。如果您链接 CRT 的静态版本,则代理将无法拦截您对运行时库的调用。