The article gives the full step-by-step guide on building Mono on Windows using Cygwin. There are number of article over the net that give the same tutorials, but no one of them gave me desired result due to different small uncertainties.
Two great articles I used as a base for my build process are:
Mono is a free open-source .NET implementation, primary oriented on Linux word, but available also for MacOS and Windows. It contains a lot of nice stuff like own C# compiler (mcs), .NET runtime (mono), .NET class library, integration with Gtk, IDE (MonoDevelop) etc.
The build process is the same as described in the articles:
- Installing stable Mono for Windows
- Installing Cygwin
- Getting sources from SVN
- Building mono with mono in cygwin
The difference is that the current article allows you to easily use compiled mono without cygwin. Also some moments mentioned only in one of articles and omitted in other are highlighted.
Installing stable precompiled Mono
This is the easiest step :).
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), combined installer is recommended. It's available from the Novell forge: http://forge.novell.com/modules/xfmod/project/?monowin32, the file is called
Important note. Download from the first link by default suggests
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 everywhere in the article x.x.x stands for the mono version you have downloaded.
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 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.
I suggest using the latest build, always available from the 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 some 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. No you see all the packages. Most of them have 'Skip' option. Select the following packages:
Make sure not to forget any of them.
DO NOT select make and glib packages. If you're interested why – read here: 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 download and configuration processes are finished.
Using the icon from the start menu or from the desktop, run the cygwin bash shell.
If you're domain user, the warning saying that not all users and groups from the domain are in your etc/* files. The warning hints you on fixing this by running two commands. Just do it. Then exit cygwin (by typing
exit and pressing Enter).
Run the cygwin again. Now it should create the /home/your_name directory (the path is relative to the cygwin root directory) and copy 4 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 some good text editor. Saying 'good' I mean "something a bit cleverer than Notepad", as you have to edit files with UNIX-like line separators. The difference is that the UNIX files use '\n', while Windows utilizes '\n\r', and this is a problem. So, I recommend Notepad++, that 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 the cygwin and install some 'clever ' notepad. Open the
c:/cygwin/home/your_name/.bashrc file and add the following text to the end:
#Environment Variables for Mono
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"
#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 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), other (like make) don't suite our goals. So now we will install them manually from the tarballs.
Go to the bash and type
mkdir -p /download/mono
It creates directories download and download/mono in the cygwin root directory. Of course, you can do the same from the Windows explorer.
No download 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 bash environment (as well as windows cmd, btw) provides nice auto-completion on Tab press. So you can type tar -xjvf /d, then click Tab and download will be auto-completed. Then print /perl and click Tab once again. Voilà.
Extract make in the same way.
Final cygwin preparations
So, a little tuning is left.
At first, we will mount mono bin, lib and other directories into our cygwin environment. It's done by typing
mount -s c:/mono/Mono-x.x.x /usr/local
Check you /usr/local directory through the Windows explorer. The bin, lib and etc directories are empty. And no go to them in the cygwin (cd /usr/local/bin) and explore their contents (dir). You see that they reflect appropriate mono directories. Now mono installation exist in the cygwin environment, is visible from there and can be (and will be) used.
mono --version to verify it. You must see information about existing mono.
No, we have to substitute Microsoft compiler (probably installed on your machine) with mono's mcs. It's done by making link to mcs that substitutes the csc.exe calls.
ln -s /usr/local/bin/mcs ./csc.exe. Then check result by typing
csc.exe --version. The result should be the same as for the
OK, we are ready with cygwin.
Subversion is the version control system, child and conqueror of the 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).
Download and install svn from here: http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91. Typically only the last but one version is published as windows installer, while the latest one is in zip. I suggest downloading both, installing svn with installer (this sets some environment variables), and then replacing installed files with those from the latest zip.
cmd and check that svn is installed by typing
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, it 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 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 2 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 the http://.
The checkout process is rather long.
Now we have to export received sources to cygwin directory. Exporting means copying all source files without subversion service files. Command-line client does it by executing
svn export . path-to-export
in the working copy (directory where you've done check out). TortoiseSVN does it from the context menu.
Export both source directories to
c:/cygwin/download/mono/mcs correspondingly. Don't create 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 2 solutions for this problem:
1. If you use 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
file in Notepad++ and click the Format > Convert to UNIX format. Then save the file and close the editor.
Fine, we are ready to build.
Standard build process consists of 3 steps:
- Configuring build options
- Building (compiling)
- 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 absolute Windows path in prefix. The prefix indicates the root directory for future installation and using such path allows us to correctly replace the mono installation with the newly built.
The process is a bit long and should exit correctly (without error messages).
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 make process doesn't try to recompile already compiled code on the next runs.
So if you got such error, just close the error message and repeat the make operation until it exits correctly.
Wonderful, mono is built (it took me 2 days to investigate all these underwater stones).
And finally type
Now all 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.