[Mono-devel-list] Issue of binary portability of a hello world application
jonpryor at vt.edu
Mon Aug 9 10:57:23 EDT 2004
On Sat, 2004-08-07 at 20:37, Ioannis Vranos wrote:
> I created a simple CLI hello world program with current C++ "Managed
> Extensions" in VS 2003 and these are the contents of the main .cpp
> #include "stdafx.h"
> #using <mscorlib.dll>
> using namespace System;
> int _tmain()
> Console::WriteLine(S"Hello World");
> return 0;
> Well when I run the executable in GNU/Linux using mono Manage.exe I
> get the error:
> ** ERROR **: file marshal.c: line 3096
> (mono_marshal_get_native_wrapper): assertion failed:
As others have already mentioned, the program generated by CL.EXE
contains native code by default, which Mono can't handle. It's also not
portable, either -- if you wanted to run your program on a Mac,
WINE-integration wouldn't help you (you'd need Mono to integrate with a
x86 emulator, which is even less likely to happen...).
What hasn't been mentioned is that: (1) this is a FAQ, and (2) the FAQ
contains more information than has been posted so far.
You need a fully-managed assembly to run under Mono, and getting
the Visual C++ .NET compiler to generate such an executable can
be difficult. You need to use only the .NET-framework
assemblies, not the C libraries (you can't use printf(3) for
example.), and you need to use the linker options /nodefaultlib
/entry:main mscoree.lib in addition to the /clr compiler flag.
You can still use certain compiler intrinsic functions (such as
memcpy(3)) and the STL. You should also see "Converting Managed
Extensions for C++ Projects from Mixed Mode to Pure Intermediate
Language"  at MSDN. Finally, you can use PEVERIFY.EXE from
the .NET SDK to determine if the assembly is fully managed.
(Beware line wrapping in the above URL.)
As has also been mentioned, using the Visual Studio 2005 Beta C++/CLI
compiler should also work, but you need to make sure you're generating
pure IL. I believe the /clr:pure or /clr:safe CL.EXE flags can be used
to do this.
More information about the Mono-devel-list