Linux support with Mono CXXI

Wololo

19-12-2011 21:45:52

Hello, the Mono team is working on CXXI, which lets managed code to interop easily with native C++ classes directly. With CXXI, it should be possible to create bindings to Ogre which work on Linux and many other operating systems, in the same way as C++/CLI makes it possible on Windows.

You can read more about it on http://tirania.org/blog/archive/2011/Dec-19.html

I'm sorry but personally I won't be able to work on it for now, but at least I wanted to let everybody know that Mogre has now the possibility to reach many more platforms if someone is willing to implement it. I think that Mogre working on Linux (and other platforms) would be greatly appreciated. I know that Axiom exists but I think that adapting Mogre to work with C++/CLI or CXXI depending on the current platform would be easier to implement than Axiom itself, thus making Mogre support more features faster since Ogre's native code is called from .NET instead of having to re-implement the entire Ogre as Axiom does.

Also, if someone has some experience with CXXI, it would be helpful if he could comment about the feasibility of such implementation.

Beauty

25-12-2011 13:10:30

Hi Wololo,

thank you very much for this very interesting news.
I know that at least a couple of Ogre/Mogre users would be happy about Mono support.

Unfortunately in our small Mogre sub-community many members have no knowledge about C++/CLI.
So I suppose we can't help in this case. It's still hard to maintain the current state with a small team.

Do you think the code is fully equal to C++/CLI?
In this case it would be possible to compile Mogre without modifications.
If CXXI uses a different syntax, then we would need to apply modifications to our autowrapper, which can be hard, because of the lack of documentation and small Mogre man power.

On the other hand - maybe Ogre C++ users are interested to switch to Mogre when they know about Mono support.

Well, I can't promise anything.
Nethertheless I'm very happy to hear about our chance.
Thanks again for your notice. :D

Beauty

25-12-2011 13:37:05

Ok, I published a notice in the Ogre main forum.
http://www.ogre3d.org/forums/viewtopic.php?f=1&t=68227

Wololo

25-12-2011 15:58:51

Do you think the code is fully equal to C++/CLI?
In this case it would be possible to compile Mogre without modifications.
If CXXI uses a different syntax, then we would need to apply modifications to our autowrapper, which can be hard, because of the lack of documentation and small Mogre man power.


I've never worked with CXXI and I'm not sure about this, but for what I've read it has nothing to do with C++/CLI but it might me much easier to create wrappers with CXXI than with C++/CLI, because it seems that the Mono project includes (with their CXXI toolchain) a tool which generates the bindings automatically, so it should be something like simply passing the C++ header files to the CXXI toolchain and you get a set of C# libraries ready to be used from pure managed code.

So it seems that with C++/CLI you get a language which can interop with native AND managed libraries, and you are left on your own to use C++/CLI to create classes that can be accessed from pure managed code. But with CXXI, you generate the wrapper libs automatically and then you just use them from managed code. Seems easier.

In the other hand, I'm thinking that since the Mogre libraries are direct wrappers to Ogre's native libs, then it might not be possible to "simply" support the CXXI wrapper, so maybe Mogre would end being just a Windows-only C++/CLI wrapper, and another project should be born which works with CXXI, because a Mogre implementation which supports both C++/CLI and CXXI I guess it would need an extra abstraction layer which can detect the operating system and use one wrapper or the other. But... the problem is that creating an independent project from Mogre only for the CXXI wrappers would mean that games/apps using Mogre will continue working only on Windows, and they would have to manually add support for both libraries/wrappers/"engines".

Beauty

25-12-2011 16:49:00

Thanks for your explanations.

Now it seems so, that CXXI only supports Mono, but no "native" .NET.
As you said, this would cause much redundant extra work.
We want to avoid splitting Mogre into two seperate projects (Windows vs. Linux/MacOS).

About 5 years ago there was an other Ogre wrapper, called OgreDotNet.
It used the tool SWIG to wrap everything automatically (using P/Invoke).
This looks nice, but the downside is a bad performance, because much redundand processing.
(e.g. for each success to an Ogre class, it created a new wrapped instance instead of pointing to an existing instance. I don't know details, but somehow like this I did read it.)
Perhaps a CXXI auto tool would run into the same problem.

By the way:
Our current autowrapping tool is based on cpp2java (with specific modifications).

smiley80

25-12-2011 17:23:26


Now it seems so, that CXXI only supports Mono, but no "native" .NET.

No, it supports both. CXXI is a normal managed assembly.

Generating a wrapper with CXXI currently works like this:
Run GCC-XML over the C++ header file, which generates an .xml file.
Use that file with the generator, which generates C# sources for the C++ classes.

The C# code calls into CXXI which dynamically emits P/Invoke methods for the native library.

I've made a small (unscientific) benchmark (after changing CXXI a bit so it also emits the SuppressUnmanagedCodeSecurity attribute):
C++/CLI: 29.0911ms
P/Invoke: 23.4889 ms
CXXI: 34.2434 ms
1 million iterations over a square root calculation.

Unfortunately, GCC-XML doesn't seem to like Ogre that much. But I think the generator can be modified so it works with Doxygen.

McDonte

26-12-2011 05:14:13

Thanks for the hint, I will check it out as soon as I find some time. If it really requires only one more step of compiling it would be quite easy to integrate into the Mogre build process. If we have to change the autowrapper it will get harder but I think it would be possible. mstoyke had a smiliar idea: he wanted the autowrapper to produce C++/CLI code AND P/Invoke code. Now we would have to do the same for CXXI.
I personally really like the idea to support Linux (and others) and I am willing to do some work for it. But if anyone is also interested in this topic and willing to help it would be great.

Jeason

26-12-2011 14:43:19

Linux support would be realy awesome :) I could offer you some help if you want (I already tried to get OGRE with cxxi working yesterday but i ran into the same problem like smiley80).

Ascendion

24-12-2012 04:09:25

I've figured out how to get GCCXML to parse the Ogre headers with minimal errors (only 11 headers fail, mostly low level allocator stuff that probably doesn't need to be wrapped in any case).. The problem is that the generator blows up trying to create the CS files for each class...

I'm going to set up to debug this in detail so it may be a few more days before I have anything more..

To clarify some things... CXXI supports both windows and linux build environments (as well as Itanium which isnt much use to us !!) so in theory it should work on any platform that Ogre supports, making it a unified solution for .Net wrapping of Ogre.... we'll see how that plays out once I get an actual wrapper created I can test with.

Ascendion

24-12-2012 07:06:39

OK -- I think we can close the book on this one... CXXI does not support templates at this time, and as of the last postings I could find, they are in the process of rebuilding the engine to use the CLANG library instead of GCCXML.....

I've joined the google group and requested a status update, but since there were no postings in the last 6 months I'm not very hopeful of a reply, or of any progress having been made.

I'm switching back to creating a swig wrapper as I must have cross platform support even if there is a performance hit.. I can always port working code from c# to c++ when I identify something that is really taking a toll on performance, but still benefit from c# during the design and testing phases.

Ascendion

22-01-2013 02:48:12

There has been activity on the LLVM/CLang front for CXXI with MSABI support.. might be worth rechecking

https://github.com/tritao/cxxi