Click here to Skip to main content
Click here to Skip to main content

HelloMono - Mono on Windows XP

By , 6 May 2004
 

Mono in Windows XP

Introduction

If you think that you have to have Visual Studio .NET in order to develop in .NET, you are in for a pleasant surprise. Mono - in Spanish the word means monkey, in geek-speak it means choice. Either way, it is most assuredly a good thing. Mono is an open source, free implementation of the .NET Framework. On May 4, 2004, the Mono project released the first public beta of their work.

A few days after I completed my previous article - hello, world - a primitive view of the state of the art, the Mono Beta 1 was released, and I wanted so badly to include a HelloMono example in my article. The only problem was that I absolutely couldn't get Mono to work on my system. Now, I am about as tech savvy as they come. I run Windows XP, Windows 2000, Solaris 10 (Software Express), Libranet, FreeBSD, and Whitebox (basically Redhat Enterprise), and occasionally a half dozen other OSes, all on the same box. When in Windows, I have Cygwin with XFree86 available and in constant use. I thought Mono would be a breeze to setup, after all it has a windows installer. Not so, I am afraid. However, all hope is not lost - it is a few days later and I have figured out how to make Mono purr, and it runs fine. Thanks to the open source community, I was able to add a bug report to the project and while the bug is still open, some kind soul posted a reasonable workaround that got me up and running.

First, here is what got me started on the whole hello, world kick again after all of these years. Kernighan and Ritchie's ubiquitous "The C Programming Language" is considered by many to be the most influential programming book of our time. Written in 1978, it immortalized the now well known phrase - "hello, world". The book states that "hello, world" is the basic hurdle to learning all languages: "to leap over it you have to be able to create the program text somewhere, compile it successfully, load it, run it, and find out where your output went. With these mechanical details mastered, everything else is comparatively easy."

You need to have some perspective to truly appreciate this statement or you might be tempted to consider it overreaching. Dennis Ritchie designed the C programming language and it was the C language that made portability possible for the Unix operating system. Unix and Linux, Minix, BSD, OSX, YouNameItOS and even Windows owe a great debt of gratitude to the language. Even the language C# is a derivative of Ritchie's C. So when in his book, it says that "hello, world" is important, we should listen.

So it is that I have taken my inspiration from K&R's work. I can think of no better method to expose the foundations of the development environment even in the year 2004 than the old, "hello, world" approach.

This article is a "hello, world" tutorial for Mono running on Windows XP:

Background

A basic understanding of .NET, the command-line, and working in Windows is assumed. Here are some good resources to help you get up to speed on these topics:

There are basically three required pieces to doing .NET development using Mono on Windows XP:

  1. Windows XP (Otherwise it wouldn't be Mono on Windows XP :) ).

  2. Mono

    More information is available at: http:www.go-mono.com

    Install Mono:

    • Download and install Mono using the Windows Installer
    • Create a monoenv.bat file in the Windows directory or somewhere else on the Path (not required, but it will make your life much easier)
      @echo off
      set MONO_PATH=d:\mono\lib
      set PATH=d:\mono\bin;d:\mono\lib;d:\ikvm\bin;d:\windows;<BR>d:\j2sdk1.4.2_03\bin
      echo mono environment established
    • Open a command prompt to test the installation
      monoenv
      
      mono environment established
      
      mcs
      
      error CS2008: No files to compile were specified
      Compilation failed: 1 error(s), 0 warnings
      
      

      If the testing fails because of a System Assembly not found error - Using Explorer find all .dll files in the mono\lib\mono\gac directory and below and copy them to mono\lib

    • run mono, should print help
      mono
      
      Usage is: mono [options] assembly
      
      Runtime and JIT debugging:
          --compile METHOD       Just compile METHOD in assembly
          --ncompile N           Number of times to compile METHOD<BR>                           (default: 1)
          --regression           Runs the regression test contained <BR>                           in the assembly
      ...
  3. UltraEdit

    Well, ok, it is not a requirement, but it will sure make things easier. Get it at http://ultraedit.com/. If you do not have a decent text editor, Notepad will work ok.

You should now be set up to develop with the Mono on the command-line.

HelloMono

This is a very simple tutorial and does not pretend to exercise Mono to its fullest.

OK, let's get started. What are the goals? Borrowing directly from Kernighan and Ritchie, these will be our goals for this tutorial:

  • Create the program text
  • Compile the program
  • Load the program
  • Run the program
  • Locate the Output

Create the program text

In order to create the program text, you will need to use a text editor of some sort. I prefer using UltraEdit, although Textpad or Notepad will work as well. Do not even bother with Word or Wordpad, these are arguably word processors and they tend to do funny things to text files. Fire up the editor and you will be ready to begin.

Here is K&R's "hello, world" C program in all its splendor, it is the model I am replicating, so I feel it is fitting to include it here:

// reader Ryan Beesley noticed that the original quote lacked an include <BR>// needed to compile so I added the following include - it is not part <BR>// of the original K&R hello, world program
#include "stdio.h"

main()
{
  printf("hello, world\n");
}

The C#.NET code that is required to print "hello, world" to the console is similarly simple:

1  using System;
2
3  namespace mynamespace {
4    public class HelloWorld {
5      public static void Main(string [] args) {
6        Console.WriteLine("hello, world");
7      }
8    }
9  }

Line 1 This is a using directive that tells the compiler that we will be referencing objects that are included in the System namespace. According to Microsoft, "The System namespace contains fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions." For our purposes, the System namespace provides the handy, dandy Console object that will allow us to print "hello, world" to the console.

Line 2 This is an empty line :) White-space, space, tab, carriage return, etc. in code (not strings) is generally considered insignificant, I tend to think of white-space as condensing to a single space or blank line.

Line 3 This is a namespace directive that tells the compiler to segregate our code in its own namespace semantically. This is not really required here, but it is good form. If you put any classes that you create in your own namespace, you will not be bitten by namespace collisions down the road. A namespace collision is what happens when there exist two semantic elements that have the same name. For instance, let's say that I create a class called Car and somewhere else within the same project someone else also creates a Car class. If I include both classes in my project, their names will collide unless they are in their own namespaces.

Line 4 This is the class declaration, our class is publicly accessible and is called HelloWorld

Line 5 The Main method. Console applications are required to have a Main method. The Main method is the method that will be executed by the operating system when the program is loaded and run. Main is public and static, it does not return anything and it takes an array of strings as arguments. static basically means that the method can be called without instantiating a HelloWorld object. The arguments are include by convention, we will not be passing in any arguments.

Line 6 "hello, world" gets printed by this call to the Console object's WriteLine method which writes the argument to the console followed by a carriage return.

Line 7 End of the Main method.

Line 8 End of the HelloWorld class definition

Line 9 End of the namespace

Save the file to your hard drive as HelloMono.cs and open a command prompt.

Compile the program

Compile the application using the Mono C# compiler:

mcs HelloMono.cs

This should produce output similar to the following, without error.

Compilation succeeded

Compiling the application will generate an executable named HelloMono.exe

Load and run the program

Loading and running the program are accomplished in a single step.

Load and run the application from the command-line by typing:
mono HelloMono.exe

Locate the Output

Console output is incredibly easy to find. Generally, it appears on the line immediately following the command itself. Running the program should produce the following output:

hello, world

Congratulations, you have completed the HelloMono tutorial. Now I know what some of you are thinking, "It took nine lines to produce the same output K&R did in four? Ha! Gotcha, I knew .NET was lame." Well, it is not that simple. Here is a minimalist C#.NET HelloWorld console example for the purist:

1  class HelloWorld {
2    public static void Main(string [] args) {
3      System.Console.WriteLine("hello, world");
4    }
5  }

It is still bigger than the K&R version, but not by much.

Conclusion

That's it, really - not radically different than the same example using the .NET Framework. Give Mono a shot, it is worth a little investment of time to have a choice.

Email the author Will Senn

References

Kernighan, B.,& Ritchie, D. (1978). The C Programming Language (pp. 5-6). New Jersey, Prentice-Hall.

Resources

Background Resources

General Resources

History

Version 1.0
This is the first version of this article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Will Senn
Program Manager University of North Texas
United States United States
Member
Will Senn is currently serving as the Director of the Decision Support Department at the University of North Texas and reports to the Senior Associate Vice President of Finance. He has served as a board member and continues to be a member of the Higher Education Data Warehousing Forum. Will is an active participant in the business intelligence and data warehousing communities, and is currently working on a PhD in Information Science.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: Go Mono on SolarissussAnonymous31 May '05 - 0:41 
I tried to build mono-1.0.6 on the latest PC-Solaris 5.10 inside a VMWARE Box and after completely install of gcc3, gmake, gnome, binutils and many other things with pkg-get and a cuple of MAKEFILE changes (especially removement of -mt statements from BUILD_GLIB_CFLAGS, BUILD_GLIB_LIBS, GLIB_CFLAGS, GLIB_LIBS) I get successful build of mono-1.0.6 and with some changes inside mono-1.0.6/data/config especially the libc.so.6 reference to libc.so.1 I get a successful 'make install'. After adding mono path to the users profile the installed version of mono could being used. The most command line tools are working fine except mcs.exe. What's going wrong?
GeneralRe: Go Mono on SolarissussAnonymous1 Aug '05 - 1:31 
Hello, thawes,
 
could you tell me if mono windows form works on Solaris? I have tried several day, but I could not get a simple windows form showed. Many thanks.
 
Best Regards
Huaiyang
GeneralRe: Go Mono on Solarismemberthawes11 Aug '05 - 16:24 
No, I am sorry, I can't. Though I cannot see why it wouldn't.
 
I retired my old Sun box just a couple weeks ago, and will be running Mono on Linux from here out.

QuestionIs Mono the ONLY free implementation of .NET?memberWill Senn8 May '04 - 2:59 
The answer, today, is no. The .NET Framework itself is downloadable from Microsoft at no charge. Of course, Mr. Gates is a proponent of charging for practically everything and this could change tomorrow:
http://www.cnn.com/2004/TECH/internet/03/05/spam.charge.ap/
 
What sets Mono apart from other free implementations is the fact that it is open source, well supported and licensed to guarantee your right to use.
 
Caveat, Mono is currently only a partial implementation of .NET, it has a long way to go before it becomes a viable replacement for .NET.
 
Will
AnswerRe: Is Mono the ONLY free implementation of .NET?memberTweety13 May '04 - 10:08 
well, you're wrong. mono is NOT a replacement for .net on windows, it's meant to be a fully cross-platform .net framework implementation. on linux it uses wine so you still have wndprocs.
and yesterday (i think) mono 1.0 beta 1 was released. this means the asp.net support is COMPLETE (albeit a few bugs). mono 1.2 will have windows.forms fully supported (you can download a preview of that on their site). and mono 2.0 will support generics, partials etc (also downloadable off their site as a preview build/source)
 
oh, and btw, mono is OPEN-SOURCE, not only free. look it up.
 
/* Peace and love,
 *     Tweety
 */

GeneralRe: Is Mono the ONLY free implementation of .NET?memberWill Senn13 May '04 - 10:22 
Tweety,
 
I'm not wrong - it is a replacement - it works fine, of course that's not it's only function as you so correctly point out.
 
Maybe you aren't replying to me, because I stated that it was OPEN-SOURCE and free.
 
Will
GeneralRe: Is Mono the ONLY free implementation of .NET?memberTweety13 May '04 - 14:44 
i am replying to you...
ok, my mistake then, i thought your question was "why make mono when there is microsoft's implementation?"...
well, then, i can say that your original question is a bit strange... WHO said mono is the only implementation of .net?! lol... besides, there is at least one more i know of (just forgot its name) -- it was made before the mono project was started i think... kinda a buggy pre-alpha that died...
 
/* Peace and love,
 *     Tweety
 */

GeneralRe: Is Mono the ONLY free implementation of .NET?memberWill Senn13 May '04 - 16:01 
ah, no problem - I wrote the original message as a response to a thread where everyone was nitpicking and telling me that the framework itself was free - yes it is, but it's also somewhat of an apples oranges comparison - mono is open source and guaranteed free, the framework is closed source, proprietary and only as free as MS makes it from one day to the next.
 
And besides, the whole premise behind my article is the choice that mono offers?
 
will
GeneralRe: Is Mono the ONLY free implementation of .NET?memberTweety14 May '04 - 6:14 
ok, now you're right. i absolutely agree.
i'd be interested to find out what happened to the other implementation, if someone remembers...
 
PS: didn't know you were the author of the article. nice job, man, got my 5 Wink | ;)
 
PPS: "UltraEdit
Well, ok, it is not a requirement, but it will sure make things easier. Get it at http://ultraedit.com/. If you do not have a decent text editor, Notepad will work ok."
 
you're kinda wrong here. why is ultraedit the ONLY decent text editor? i've been using emeditor for years now and it's awesome! (well, doesn't compare to vim, another favorite of mine, but on the other hand vim is a little difficult to learn...)
 
/* Peace and love,
 *     Tweety
 */

AnswerRe: Is Mono the ONLY free implementation of .NET?memberreflog22 Aug '04 - 7:05 
This statent is incorrent.
There is another open source project to replicate .NET under other platforms. It's called Portable.Net
or DotGNU Project. http://www.dotgnu.org/
AnswerRe: Is Mono the ONLY free implementation of .NET?sussIvan Deras13 Dec '04 - 19:43 
What about Portable.NET? why no one is speaking about Portable.NET? Actually they have a nearly complete SWF implementation (they aren't using Wine on Linux) you can see it at:
http://www.getdotgnu.com/screenshots
http://pnet.homelinux.org/
 
And it is very Portable (like the name saids) ...
AnswerRe: Is Mono the ONLY free implementation of .NET?sussAnonymous8 Feb '05 - 3:44 
There is also GNU's Portable.NET (http://www.dotgnu.org/) - I'm not sure what state it's at, I haven't looked for a while.
GeneralMonoeditorMarc Clifton7 May '04 - 16:51 
in Spanish the word means monkey, in geek-speak it means choice.
 
I thought it was the kissing disease.
 
Roll eyes | :rolleyes:
 
(5, BTW)
 
Marc
 
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
GeneralRe: MonomemberColin Angus Mackay8 May '04 - 0:35 
Marc Clifton wrote:
I thought it was the kissing disease
 
Confused | :confused:
 

"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
 
Coming soon: The Second EuroCPian Event


GeneralRe: MonoeditorMarc Clifton8 May '04 - 2:35 
Mono, the kissing disease[^]
 
Good grief. I'm sure the author wasn't thinking that he'd be getting posts regarding this topic. Roll eyes | :rolleyes:
 
Marc
 
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
GeneralRe: MonomemberWill Senn8 May '04 - 2:49 
No Kidding, where's my moderate down comment button...
GeneralMono and MyXaml?editorMarc Clifton8 May '04 - 3:25 
Will Senn wrote:
No Kidding, where's my moderate down comment button...
 
Indeed. Getting the subject back on track, you're article is very timely! I've been wanting to see how MyXaml works on Mono. Should be fun!
 
I really enjoyed your article, BTW.
 
Marc
 
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
GeneralRe: Mono and MyXaml?memberWill Senn8 May '04 - 5:42 
Marc,
 
Thanks for the kind words, I enjoyed writing about mono - it's on the edge and a lot of the stuff I write about is dusty...
 
Will
GeneralRe: Mono and MyXaml?editorMarc Clifton10 May '04 - 7:32 
Well, I'm impressed. I got the core MyXaml parser up and running in about 30 minutes, total time from Mono installation to compilation and Hello MyXaml application, THANKS TO YOUR GREAT INSTRUCTIONS!!!
 
Marc
 
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
GeneralRe: Mono and MyXaml?memberWill Senn10 May '04 - 13:35 
Marc,
 
Great, so when are you going to write up the MyXaml article Wink | ;)
 
Will
GeneralRe: MonomemberColin Angus Mackay8 May '04 - 6:32 
Marc Clifton wrote:
Good grief. I'm sure the author wasn't thinking that he'd be getting posts regarding this topic
 
Probably not, but I'd never heard of it before. At least not described the way you did. But I am now more educated.
 

"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
 
Coming soon: The Second EuroCPian Event


GeneralCoolmemberJudah Himango7 May '04 - 10:11 
Great to see Mono examples on CodeProject!
 
I'm really suprised you had so much trouble getting Mono running; my experience on both my work and home machines was simply running the installer, then compiling with the mcs.exe Mono compiler tool. OTOH, it is the first of several betas before release 1 later this year...
 
If I may offer a suggestion for compiling without an IDE: Textpad (www.textpad.com) is one real nice text editor. In addition to free syntax packages (including one for C#), it allows easy linkage to external tools for whatever purpose you please. I hooked it up with the Mono compiler, Sun's Java compiler, and Microsoft's JScript.NET compiler, which basically turned TextPad into a Mono, Java, and JScript.NET IDE all in one. Smile | :)
 
As a side note, the Mono guys are working on an IDE for Linux: www.monodevelop.com. Additionally, if I recall right, the SharpDevelop IDE had been (still is?) planning on supporting Mono and Visual GTK# form designer.
 
#include "witty_sig.h"
GeneralRe: CoolmemberWill Senn7 May '04 - 10:18 
Thanks for the kind words. Textpad is pretty cool, I use UltraEdit - but there's a lot of common ground between them. Sharp Develop comes with .net support, but I don't see any options for using mcs (may be buried in the options...)
 
Are you using XP? I didn't have problems with mono on win2k.
 
Will
GeneralRe: CoolmemberJeff Varszegi7 May '04 - 10:53 
Great article!
 
I use EditPlus for text editing; it's got some pretty cool features, too. I'm going to download Mono this weekend and play around with it.
 
Have you used GTK# at all?
 
-Jeff
 
here, bloggy bloggy
GeneralRe: CoolmemberWill Senn7 May '04 - 11:08 
GTK# - pain and suffering... I've tried to get it working - guess I'm cursed with these things. Probably works flawlessly on Linux. The article to check out for the GTK# is the wiki:
http://www.nullenvoid.com/gtksharp/wiki/index.php
 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 7 May 2004
Article Copyright 2004 by Will Senn
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid