July 02, 2003

Mono First Impressions

I've been working with .NET a lot at work and was interested to note that the mono team have released a new version: Mono 0.25. I downloaded the windows version to see what it was like.

Mono 0.25 for Windows comes as an NSIS installer that dumps a bunch of files in c:\program files\mono-0.25 (by default), with subdirectories like bin, lib etc. The compiler and run-time stub are all in the bin directory (with apologies for those who could have guessed that) and all of the runtime library is in lib. There is some help provided in the man directory, but of course these are man format and pretty useless to the average windows user.

The installer does not create any program icons or provide any useful help, be prepared to work it out using google. Therefore, it took me a minute of googling to work out that I needed to set the MONO_PATH variable to make my software run - the error message given by mono was a less than useful "The assembly corlib.dll was not found or could not be loaded. It should have been installed in the `c:/Mono/install/lib' directory."

The following is a batch file that should set the environment up to allow you to compile and run with mono:

@echo off
set PATH=%PATH%;c:\progra~1\mono-0.25\lib
set MONO_PATH=c:\progra~1\mono-0.25\lib

of course, you should probably add these to your windows environment variables if you plan to use mono often.

To compile you just type:
mcs mycsharpfile.cs

The compiler reports "Compilation succeeded" if everything is OK, and a very scary error message like this if it isn't:
syntax error, expecting ABSTRACT BOOL BYTE CHAR CLASS CONST DECIMAL DELEGATE DOUBLE ENUM EVENT EXPLICIT EXTERN FLOAT IMPLICIT INT INTERFACE INTERNAL LONG NEW OBJECT OVERRIDE PRIVATE PROTECTED PUBLIC READONLY SBYTE SEALED SHORT STATIC STRING STRUCT UINT ULONG UNSAFE USHORT VIRTUAL VOID VOLATILE CLOSE_BRACE OPEN_BRACKET TILDE IDENTIFIER
C:\Projects\monotest\\clhelloworld.cs(13) error CS8025: : Parsing error
Mono.CSharp.yyParser.yyException: irrecoverable syntax error
at Mono.CSharp.CSharpParser.yyparse(yyInput yyLex)
at Mono.CSharp.CSharpParser.parse()
Compilation failed: 1 error(s), 0 warnings

To run the program using mono's runtime environment (CLR equivalent) you have to preclude your command with mono, e.g.
mono mycsharpbin.exe

If you don't do this, then the program will run with the standard .NET framework (if you have it installed). I successfully compiled a simple hello world style application using the mono compiler and then ran it on both the .NET framework and the mono version of the framework - clever stuff.

Definitely one to keep an eye on. When I get a chance to try something more interesting than Hello World I'll post another report.

Posted by Simon at July 2, 2003 05:30 PM
Feedback

Thanks. I was close to giving up before I find this blog entry.

Posted by RichB at Mar 17, 2004 10:30 AM