Click here to Skip to main content
15,400,390 members
Articles / Operating Systems / Windows
Posted 12 Jul 2007

Tagged as


53 bookmarked

Building Mono on Windows: The Final Battle

Rate me:
Please Sign up or sign in to vote.
4.79/5 (11 votes)
12 Jul 2007CPOL8 min read
Defines the full process of building Mono on Windows with Cygwin


The article gives a full step-by-step guide to building Mono on Windows using Cygwin. There are a number of articles on the net that gives the same tutorial, but none of them gave me the desired result due to different uncertainties.

Two great articles I used as a base for my build process are:


Mono is a free Open-Source .NET implementation, primarily oriented for the Linux world, but available also for MacOS and Windows. It contains a lot of nice stuff like its own C# compiler (mcs), .NET runtime (mono), .NET class library, integration with Gtk, IDE (MonoDevelop), etc.

Building Process

The build process is the same as described in the articles:

  1. Installing stable Mono for Windows
  2. Installing Cygwin
  3. Getting sources from SVN
  4. Building Mono with Mono in Cygwin

The difference is that this article allows you to easily use compiled Mono without Cygwin. Also, some steps mentioned only in one of the articles and omitted in others are highlighted.

Installing Stable Precompiled Mono

This is the easiest step :).

It is available at this link, just use the Stable installer.

If you want some advanced experience in the future (I plan to try building MonoDevelop), the combined installer is recommended. It's available from Novell forge, and the file is called "mono-x.x.x-gtksharp-x.x.x-win32-exp-x.x.exe" .

Important note. Download from the first link; by default, it suggests the C:\Program Files\Mono-x.x.x directory. You should alter it so that the destination path doesn't contain spaces. C:\mono\Mono-x.x.x is recommended. Here and in the rest of this article, x.x.x stands for the Mono version you have downloaded.

Installing Cygwin


It's highly recommended that your Windows login name doesn't contain spaces. If it does, bad for you, but you can fix this (read this, page 2, question 13).

If you have had unsuccessful attempts to install Cygwin in the past, remove it first. See here (section 1) for details.

Installing Cygwin

I suggest using the latest build, always available from

Download the "setup.exe" file, put it somewhere on the disk, and run it. Make sure to have enough free space on this disk (at least 100M).

After the setup is ran, select the default settings (destination path, UNIX line separators, etc.), pick a mirror from the list, and the list of available packages will be displayed to you.

Using the View button, switch to the Full view mode. Now you see all the packages. Most of them have a 'Skip' option. Select the following packages:

  • automake
  • bison
  • gcc
  • gdb
  • gettext
  • intltool
  • libiconv
  • libtool
  • pkg-config

Make sure not to forget any of them.

Do not select the make and glib packages. If you're interested in why - read this tutorial (installing Cygwin).

If you're OK with vim, select it too.

Now click the Next button and wait until the download and configuration processes are finished.

Configuring Cygwin

Using the icon from the Start menu or from the desktop, run the Cygwin bash shell.

If you are a domain user, you will get a warning saying that not all users and groups from the domain are in your etc/* files. The warning hints you to fix this by running two commands. Just do it. Then exit Cygwin (by typing exit and pressing Enter).

Run Cygwin again. Now it should create the /home/your_name directory (the path is relative to the Cygwin root directory) and copy four files to it: .bash_history, .bash_profile, .bashrc, .inputrc. Periods in the beginning of their names indicate that these are UNIX hidden files.

Until you are familiar with vi/vim, you need a good text editor. By 'good', I mean "something a bit cleverer than Notepad", as you have to edit files with UNIX-like line separators. The difference is that UNIX files use '\n', while Windows utilizes '\n\r', and this is a problem. So, I recommend Notepad++, which is available here. It will help us once again later.

So, if you don't like (don't know) vim, exit Cygwin and install the 'clever' Notepad. Open the c:/cygwin/home/your_name/.bashrc file and add the following text to the end:

#Environment Variables for Mono
export PATH="/usr/local/bin:/usr/local/lib:$PATH:/usr/local/icu/bin"
export ACLOCAL_FLAGS="-I /usr/share/aclocal"
export CPPFLAGS="$CPPFLAGS -I/usr/local/include"
export LDFLAGS="$LDFLAGS -L/usr/local/lib"
export CC="gcc -mno-cygwin"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig"
export LD_LIBRARY_PATH="/usr/local/lib:/usr/lib"
export MONO_PATH="/usr/local/lib:/usr/lib:$MONO_PATH"
export MONO_CFG_PATH="/usr/local/etc:/usr/etc:$MONO_CFG_PATH"

#Environment variables for .NET if not already in your Windows PATH
#These variables could be needed by older Mono build systems
#export PATH=$PATH:`GetNetSdkLocation -cs msnet_1.1`/v1.1.4322
#export PATH=$PATH:`GetNetSdkLocation -cs msnetsdk_1.1`/Bin

(Thanks to Kevin Shockey's article.)

This will set the necessary environment variables every time you run Cygwin. Exit Cygwin and run it again.

Installing Extra Packages

Some necessary packages are not available from the Cygwin repository (like perl-XML-Parcer), others (like make) don't suite our goals. So now, we will install them manually from the tarballs.

Go to bash and type:

mkdir -p /download/mono

It creates the directories download and download/mono in the Cygwin root directory. Of course, you can do the same from Windows Explorer.

Now download the proper version of make from the Mono official site using this link. Save the file to the c:/cygwin/download directory. Also download the Perl-XML parser from this link.

Now we have to install (actually simply extract) them:

tar -xjvf /download/perl-XML-Parser-2.34-1.tar.bz2

Seems not very beautiful, really. But the bash environment (as well as Windows cmd, by the way) provides nice auto-completion on Tab press. So you can type tar -xjvf /d, then click Tab, and the download will be auto-completed. Then print /perl and click Tab once again. Voila!

Extract make in the same way.

Final Cygwin Preparations

A little tuning is left.

At first, we will mount Mono bin, lib and other directories into our Cygwin environment. This is done by typing:

mount -s c:/mono/Mono-x.x.x /usr/local

Check your /usr/local directory through Windows Explorer. The bin, lib, and etc. directories are empty. Go to them in Cygwin (cd /usr/local/bin) and explore their contents (dir). You see that they reflect the appropriate Mono directories. Now the Mono installation exists in the Cygwin environment, is visible from there, and can be (and will be) used.

Type mono --version to verify it. You must see information about the existing Mono.

Now we have to substitute the Microsoft compiler (probably installed on your machine) with Mono's mcs. It's done by making a link to mcs that substitutes the csc.exe calls.

Type ln -s /usr/local/bin/mcs ./csc.exe. Then check the result by typing csc.exe --version. The result should be the same as for mcs --version.

OK, we are ready with Cygwin.

Installing Subversion

Subversion is the version control system, child and conqueror of CVS. We need it to obtain the latest Mono and mcs source code.

You can choose between the command-line tool (original distribution) or the GUI implementation (TortoiseSVN).

Command-line SVN

Download and install SVN from here. Typically, only the last but one version is published as a Windows installer, while the latest one is in zip. I suggest downloading both, installing SVN with the installer (this sets some environment variables), and then replacing the installed files with those from the latest zip.

No call cmd and check that SVN is installed by typing svn --version.


TortoiseSVN is a nice and easy to use Windows Subversion client. It integrates with Windows Explorer. It can be downloaded from here.

Making Repository Checkout and Sources Export

Now we have to check out the Mono and mcs repositories, which means get Mono and mcs sources from the special Subversion server.

Using the command-line client, checkout is done with svn co path-to-repository from the command line in the directory where you want to get the sources. Using TortoiseSVN - just by right-clicking on the directory, selecting Checkout, and entering the path to the repository.

Create some directory for the sources and two directories inside it called mono and mcs. You will need approximately 200M of free space.

Now make checkouts: svn:// - to mcs, svn:// - to Mono.

Note: If you get error messages, change svn:// in the addresses to http://.

The checkout process is rather long.

Now we have to export the received sources to Cygwin directory. Exporting means copying all the source files without Subversion service files. The command-line client does it by executing:

svn export . path-to-export

in the working copy (directory where you've done the check out). TortoiseSVN does it from the context menu.

Export both source directories to c:/cygwin/download/mono/mono and c:/cygwin/download/mono/mcs correspondingly. Don't create the target directories if using SVN; on the contrary, create them manually before exporting with TortoiseSVN.

The problem. By default, your Subversion client is configured to use CRLF line separators (Windows-style). And this will be the problem, especially with one file - mkinstalldirs from the mcs repository. There are two solutions for this problem:

  1. If you use a command-line client, use the following command for export:
    svn export . c:\cygwin\download\mono\mcs --native-eol LF
  2. Unfortunately, TortoiseSVN doesn't allow you to specify export switches. So, in this case, open the c:/cygwin/download/mono/mcs/mkinstalldirs file in Notepad++ and click Format > Convert to UNIX format. Then save the file and close the editor.

Fine, we are ready to build.


The standard build process consists of three steps:

  1. Configuring build options
  2. Building (compiling)
  3. Installing (copying compiled files)

First, from the Cygwin bash shell, go to the /download/mono/mono directory. Type:

./ --prefix=C:/mono/Mono-x.x.x --with-preview=yes

(Of course, substitute the path to your real Mono installation.)

The trick is that we use the absolute Windows path in the prefix. The prefix indicates the root directory for future installation, and using such a path allows us to correctly replace the Mono installation with the new build.

The process is a bit long and should exit correctly (without error messages).

Now type:


This process is really long (up to 2 hours) and may crash. On my machine, it consequently throws the 'mono incorrect operation' error. The good news is that the make process doesn't try to recompile already compiled code in the next runs.

So if you get such an error, just close the error message and repeat the make operation until it exits correctly.

Wonderful, Mono is built (it took me two days to investigate all these underwater stones).

And finally type:

make install

Now all the created files are copied to prefix, which is our Mono installation directory.

After this, type mono --version and check that it corresponds to the one you've downloaded. Also the word 'tarball' will be present after the version number.



  • 12th July, 2007: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Eugene Mirotin (Guard)
Software Developer
Belarus Belarus
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pin
Look8721-Mar-12 19:05
MemberLook8721-Mar-12 19:05 
GeneralNow how about OpenVMS... Pin
PIEBALDconsult15-Oct-08 13:11
professionalPIEBALDconsult15-Oct-08 13:11 
GeneralCode Differences Pin
Jon-Hawkins12-Jul-07 2:40
MemberJon-Hawkins12-Jul-07 2:40 
GeneralRe: Code Differences Pin
Eugene Mirotin (Guard)12-Jul-07 3:09
MemberEugene Mirotin (Guard)12-Jul-07 3:09 
GeneralRe: Code Differences Pin
Jon-Hawkins12-Jul-07 4:19
MemberJon-Hawkins12-Jul-07 4:19 
GeneralRe: Code Differences Pin
cfrankert12-Jul-07 5:29
Membercfrankert12-Jul-07 5:29 
GeneralRe: Code Differences Pin
melchizedek13-Jul-07 3:27
Membermelchizedek13-Jul-07 3:27 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.