Click here to Skip to main content
Click here to Skip to main content
Go to top

Building Mono on Windows: The final battle

, 12 Jul 2007
Rate this:
Please Sign up or sign in to vote.
Defines the full process of building Mono on Windows with Cygwin.

Introduction

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

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 Smile | :) .

It is available here: http://www.mono-project.com/Downloads, 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: http://forge.novell.com/modules/xfmod/project/?monowin32, 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

Pre-steps

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

If you have had unsuccessful attempts to install Cygwin in the past, remove it first. See http://www.ondotnet.com/pub/a/dotnet/2005/02/07/monowindows.html (section 1) for details.

Installing Cygwin

I suggest using the latest build, always available from http://www.cygwin.com.

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 http://shana.iidbbs.com/en/mono_cygwin_tutorial.html (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: http://notepad-plus.sourceforge.net/uk/download.php. 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: http://www.go-mono.com/archive/helper/make-3.80-1.tar.bz2. Save the file to the c:/cygwin/download directory. Also download there the Perl-XML parser: http://prdownloads.sourceforge.net/cygwin-ports/perl-XML-Parser-2.34-1.tar.bz2?download.

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 you /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: http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91. 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

TortoiseSVN is a nice and easy to use Windows Subversion client. It integrates with Windows Explorer. It can be downloaded from here: http://tortoisesvn.net/downloads.

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://anonsvn.mono-project.com/source/trunk/mcs - to mcs, svn://anonsvn.mono-project.com/source/trunk/mono - 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:
  2. svn export . c:\cygwin\download\mono\mcs --native-eol LF
  3. 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.

Building

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:

./autogen.sh --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:

make

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.

Congratulations!

License

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

Share

About the Author

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

Comments and Discussions

 
GeneralMy vote of 5 PinmemberLook8721-Mar-12 19:05 
GeneralNow how about OpenVMS... PinmemberPIEBALDconsult15-Oct-08 13:11 
GeneralCode Differences PinmemberJon-Hawkins12-Jul-07 2:40 
GeneralRe: Code Differences PinmemberEugene Mirotin (Guard)12-Jul-07 3:09 
GeneralRe: Code Differences PinmemberJon-Hawkins12-Jul-07 4:19 
GeneralRe: Code Differences Pinmembercfrankert12-Jul-07 5:29 
GeneralRe: Code Differences Pinmembermelchizedek13-Jul-07 3:27 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 12 Jul 2007
Article Copyright 2007 by Eugene Mirotin (Guard)
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid