[Mono-devel-list] Issue of binary portability of a hello world application

Jonathan Pryor 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
> file:
> #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:
> (method->signature->pinvoke)
> aborting...
> Aborted

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.

See: http://www.mono-project.com/about/technical.html#q63

In particular:

        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" [1] at MSDN. Finally, you can use PEVERIFY.EXE from
        the .NET SDK to determine if the assembly is fully managed.

[1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vcgrfconvertingmanagedextensionsforcprojectsfrommixed-modetopureil.asp

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

See also:

 - Jon

More information about the Mono-devel-list mailing list