34

Does Mono .NET support and compile C++ / CLI?

If not, do you know if they have any plans of supporting it?

7 Answers 7

26

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.

You can compile using the MS .NET compiler and run in mono with these restrictions:

  1. 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#?)

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

Note that MS itself will eventually drop C++/CLI, so don't invest too much on it and switch to C#.

Sign up to request clarification or add additional context in comments.

12 Comments

"MS itself will eventually drop C++/CLI" Could you explain why you think that ? It seems very unlikely to me.
Managed C++ is already unsupported and discontinued, it didn't take them long to do that. Now go count the news items related to C++/CLI in the last year or two, the blog posts, the announcements. Connect the dots.
Managed C++ was dropped because of significant usability issues. C++/CLI as an interop language will not go away but it is already a second-class citizen for GUI - WPF is not and never will be supported.
It is pretty funny that the C++ is dead comments continue right up until late 2011. C++ is doing so well at Microsoft (WinRT) that some people are now worried that it is C# that is in trouble. I do not think that. At any rate, you can now develop C++ apps with XAML so some of the commenters above must be surprised.
I think the real unspoken question here is what Mono has to replace that gap: How do I write my bindings to C++ libraries for C# projects to use? It's one thing to just say "C++/CLI sucks, so we won't do it" without going into the question of what else to use.
|
17

Mono has recently made some pretty big strides with C++ interoperability in CXXI.

From this posting, the short story is that the new CXXI technology allows C#/.NET developers to:

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

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.

3 Comments

What's the current status of this project? Is it in a usable state? There hasn't been any activity in the repo in about a year and the discussion group is pretty bare.
Would be interesting if there is any plans to support this in the future.
It appears to be dead.
11

Mono is able to run 'pure' assemblies generated by C++/CLI, ie. ones that don't contain any native code. The various /clr options supported by the C++ compiler are documented on 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.

I don't believe Microsoft document the format for including native code in an assembly, so supporting this is difficult.

Comments

10

This is a very old question with very interesting answers after some years.
As of right now tritao/CppSharp is the most actively developed fork of mono/cxxi which was moved back to the mono repository in 2013 and is being actively developed since, The current tree can be found at mono/CppSharp

Their readme is here and 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

It also comes with a lot of cool AST stuff and a parser.

Comments

2

No, C++/CLI is not supported under Mono and likely never will be although generating pure IL using MS compilers would allow totally managed code to run under 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-documented albeit with problems.

1 Comment

What kind of problems are you thinking of?
2

On Mono 2.4 you can run C++/CLI applications which were compiled under e.g. Visual Studio 2008 with /clr:safe switch.

Comments

0

go here and look under "Missing Languages". But just because you cant compile does not mean that you cant run. You can compile your C++ code using the framework sdk and try running it using mono. Worth trying anyway.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.