34

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

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

Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636

7 Answers7

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

Sklivvz
  • 30,601
  • 24
  • 116
  • 172
lupus
  • 3,963
  • 1
  • 18
  • 13
  • 22
    "MS itself will eventually drop C++/CLI" Could you explain why you think that ? It seems very unlikely to me. –  Oct 11 '08 at 12:43
  • 8
    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. – lupus Oct 12 '08 at 08:59
  • Count the news items,blog posts,announcements, related to C++ (coming from Microsoft) and compare to C#, ASP.NET, etc. Does that mean MS will drop C++ ? –  Oct 12 '08 at 23:23
  • An old and established language has less development needs and still C++ from MS has seen much more exposure than C++/CLI. But it's your money, so if you want to invest in C++/CLI it's up to you, I'm just giving my advice: people should stay away from C++/CLI and doubly so if they value portability. – lupus Oct 13 '08 at 07:37
  • if they value portability they should stay away from C# too. I think MS will keep C++/CLI forever, think that they support Iron* languages and they have an even smaller userbase. – gbjbaanb Dec 04 '08 at 22:53
  • 12
    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. – Andy Dent Jan 26 '09 at 05:33
  • 4
    "Managed C++ is already unsupported and discontinued, it didn't take them long to do that": This is why I hate Microsoft with a passion bordering on pathological. After wasting about year of my life studying this half-assed language, not to mention the countless $ I spent in buying overpriced Managed C++ books from the Microsoft press, the language was uncerimonuosly and quietly dropped. VB6 (though a rubbish language, had a huge following) - was similarly killed of callously by MS - despite loud protesttaions from the customer base. I for one welcome our new overlords Google et al – Stick it to THE MAN Apr 04 '10 at 13:27
  • 2
    @StickittoTHEMAN I'm no M$ fanboy but killing VB6 was surely one of the better things M$ has done - that bitch was ugly. As for C++CLI it has a niche for interop but its ugly too - outside of interop you either need and use C++ or enjoy C#. C++CLI was never going to be anything for developers or M$ to invest in - you should have spend your book money else where. – Ricibob Sep 20 '11 at 20:21
  • 9
    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. – Justin Jan 29 '12 at 10:31
  • @Justin I'd just like to point out the following. The C++ variant used for WinRT is C++/CX (similar case as the CLR and C++/CLI), which includes a number of features which are not yet (partial classes, async continuations, etc.), or will never* be (runtime classes), part of the C++11 standard. *in the foreseeable future. – Gabriel Garcia Apr 20 '13 at 20:37
  • 14
    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. – John Nov 19 '14 at 16:22
  • 4
    C++/CLR Still kicking as of VS 2017 – jjxtra Jun 17 '17 at 14:43
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.

Justin
  • 8,853
  • 4
  • 42
  • 42
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.

Rob Walker
  • 46,588
  • 15
  • 99
  • 136
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.

Behrooz
  • 1,696
  • 2
  • 32
  • 54
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.

Andy Dent
  • 17,578
  • 6
  • 88
  • 115
2

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

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.

Kinjal Dixit
  • 7,777
  • 2
  • 59
  • 68