Mono .NET 是否支持和编译 C++/CLI?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/183377/
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
Does Mono .NET support and compile C++ / CLI?
提问by Brian R. Bondy
Does Mono .NET support and compile C++ / CLI?
Mono .NET 是否支持和编译 C++/CLI?
If not, do you know if they have any plans of supporting it?
如果没有,你知道他们是否有任何支持它的计划吗?
采纳答案by lupus
We don't have a compiler for C++/CLI, it would be a very large undertaking for a very small userbase. Consider also that the C++/CLI spec is inherently flawed and non-portable, so being able to compile it wouldn't help much in the general case.
我们没有用于 C++/CLI 的编译器,对于非常小的用户群来说,这将是一项非常艰巨的任务。还要考虑到 C++/CLI 规范本质上有缺陷且不可移植,因此在一般情况下能够编译它不会有太大帮助。
You can compile using the MS .NET compiler and run in mono with these restrictions:
您可以使用 MS .NET 编译器进行编译并在具有以下限制的单声道中运行:
run with mono on any system if the C++/CLI app is pure managed (but then, why use such an ugly language and not C#?)
run with mono on windows in the other cases (C++/CLI apps are in general non-portable and include native code, so they can run only on windows and are uninteresting for the major objective of mono which is to run managed programs on Linux)
如果 C++/CLI 应用程序是纯托管的,则在任何系统上使用 mono 运行(但是,为什么使用如此丑陋的语言而不是 C#?)
在其他情况下,在 Windows 上使用 mono 运行(C++/CLI 应用程序通常不可移植并且包含本机代码,因此它们只能在 Windows 上运行,并且对于在 Linux 上运行托管程序的 mono 的主要目标没有兴趣)
Note that MS itself will eventually drop C++/CLI, so don't invest too much on it and switch to C#.
请注意,MS 本身最终会放弃 C++/CLI,因此不要在它上面投入太多并切换到 C#。
回答by Justin
Mono has recently made some pretty big strides with C++ interoperability in CXXI.
Mono 最近在CXXI 中的C++ 互操作性方面取得了一些相当大的进步。
From this posting, the short story is that the new CXXI technology allows C#/.NET developers to:
从这篇文章中可以看出,新的 CXXI 技术允许 C#/.NET 开发人员:
- Easily consume existing C++ classes from C# or any other .NET language
- Instantiate C++ objects from C#
- Invoke C++ methods in C++ classes from C# code
- Invoke C++ inline methods from C# code (provided your library is compiled with -fkeep-inline-functions or that you provide a surrogate library)
- Subclass C++ classes from C#
- Override C++ methods with C# methods
- Expose instances of C++ classes or mixed C++/C# classes to both C# code and C++ as if they were native code.
- 轻松使用来自 C# 或任何其他 .NET 语言的现有 C++ 类
- 从 C# 实例化 C++ 对象
- 从 C# 代码调用 C++ 类中的 C++ 方法
- 从 C# 代码调用 C++ 内联方法(前提是您的库是使用 -fkeep-inline-functions 编译的,或者您提供了代理库)
- 从 C# 继承 C++ 类
- 用 C# 方法覆盖 C++ 方法
- 向 C# 代码和 C++ 公开 C++ 类或混合 C++/C# 类的实例,就好像它们是本机代码一样。
CXXI is the result of two summers of work from Google's Summer of Code towards improving the interoperability of Mono with the C++ language.
CXXI 是 Google 的 Summer of Code 为提高 Mono 与 C++ 语言的互操作性而进行的两个夏天工作的结果。
回答by Behrooz
This is a very old question with very interesting answers after some years.
As of right now tritao/CppSharpis the most actively developed fork of mono/cxxiwhich was moved back to the monorepository in 2013 and is being actively developed since, The current tree can be found at mono/CppSharp
这是一个非常古老的问题,几年后会有非常有趣的答案。
截至目前,tritao/CppSharp是开发最活跃的mono/cxxi 分支,该分支于 2013年移回mono存储库,并且正在积极开发,当前树可以在mono/CppSharp找到
Their readme is hereand the features for the 'generator' are:
他们的自述文件在这里,“生成器”的功能是:
- Multiple backends: C++/CLI and C# P/Invoke
- Multiple ABIs: Itanium, MS, ARM, iOS and iOS64
- Multiple platforms: Windows, OS X and Linux
- Virtual table overriding support
- Multiple inheritance support
- Easily extensible semantics via user passes
- Work-in-progress support for STL (C++/CLI only)
- Strongly-typed customization APIs and type maps
- 多个后端:C++/CLI 和 C# P/Invoke
- 多个 ABI:Itanium、MS、ARM、iOS 和 iOS64
- 多平台:Windows、OS X 和 Linux
- 虚拟表覆盖支持
- 多重继承支持
- 通过用户通行证轻松扩展语义
- 对 STL 的正在进行的支持(仅限 C++/CLI)
- 强类型自定义 API 和类型映射
It also comes with a lot of cool AST stuff and a parser.
它还带有很多很酷的 AST 东西和一个解析器。
回答by Rob Walker
Mono is able to run 'pure' assemblies generated by C++/CLI, ie. ones that don't contain anynative code. The various /clr options supported by the C++ compiler are documented on MSDN.
Mono 能够运行由 C++/CLI 生成的“纯”程序集,即。那些不包含任何本机代码的。C++ 编译器支持的各种 /clr 选项记录在MSDN 上。
There is currently no support for compiling C++/CLI. There has been some work on modifying GCC to emit IL, but it isn't complete (and doesn't appear active). See this article.
目前不支持编译 C++/CLI。已经有一些修改 GCC 以发出 IL 的工作,但它并不完整(并且看起来并不活跃)。请参阅这篇文章。
I don't believe Microsoft document the format for including native code in an assembly, so supporting this is difficult.
我不相信 Microsoft 记录了在程序集中包含本机代码的格式,因此支持这一点很困难。
回答by Rob Walker
On Mono 2.4 you can run C++/CLI applications which were compiled under e.g. Visual Studio 2008 with /clr:safe switch.
在 Mono 2.4 上,您可以运行在例如 Visual Studio 2008 下使用 /clr:safe 开关编译的 C++/CLI 应用程序。
回答by Andy Dent
No, C++/CLI is not supportedunder Mono and likely never will be although generating pure IL using MS compilers would allow totally managed code to run under Mono.
不,C++/CLI在 Mono 下不受支持,并且可能永远不会支持,尽管使用 MS 编译器生成纯 IL 将允许在 Mono 下运行完全托管的代码。
As an interop language, C++/CLI exists to make it possible to call unmanaged code. The other alternative is using P/Invoke which is well-documentedalbeit with problems.
作为一种互操作语言,C++/CLI 的存在使得调用非托管代码成为可能。另一种选择是使用 P/Invoke,尽管存在问题,但它已被很好地记录在案。

