[Mono-list] Mono linux question

Jonathan Pryor jonpryor at vt.edu
Tue Aug 2 20:35:51 EDT 2005


On Tue, 2005-08-02 at 10:37 -0400, JamesGHS at aol.com wrote:
> I am porting some C++ windows code to linux.  I came across code that
> was using:
> 
> #using <mscorlib.dll>
> #using <System.xml.dll>
> 
> using namespace System;
> using namespace System::Xml;
> 
> In my research i came across Mono.  I wanted to know if i loaded mono
> onto linux if that code would still work in C++ on the linux box.  

It will not work.  The above code uses Microsoft's Managed Extensions
for C++.  If you compile the code with VS.NET, you will get a "mixed
mode" assembly, which contains both native machine code and managed IL.

The native machine code won't work on x86 Linux (never mind on PPC or
anywhere else) because it assumes the presence of Microsoft libraries
(msvcrt.dll, calling conventions, hidden library features...).

Attempting to recompile the code for Mono won't work, as there is no
other Managed Extensions for C++ compiler.

That leaves two choices:

(1) Rewrite the code in C and C#, which can be handled portably between 
    Mono and .NET.  You might also try using SWIG (http://www.swig.org),
    which will generate C wrapper code over existing C++ classes, and 
    may simplify the C++/C/C# integration work.

(2) Port the Managed Extensions for C++ code to C++/CLI, the new,
    improved, and ECMA-standardized replacement.  Then compile this code
    with VS.NET 2005 using /clr:pure or /clr:safe (IIRC).  This should 
    generate 100% IL assemblies.

    C++/CLI assemblies might not run on Mono *now*, but it will be 
    *possible* to run them eventually (as opposed to the current
    mixed-mode assemblies, which will never run cross-platform).

 - Jon




More information about the Mono-list mailing list