Building Mono on Windowsby Kevin Shockey
Mono, the open source implementation of the CLR, is not just for non-Microsoft
platforms. In this article I will walk you through the three phases required
to build Mono on Windows without using
the .NET framework. There have already been several build processes available
before, but they mostly required using the
csc.exe C# compiler from the Microsoft
.NET framework. This process is distinct in that you will use the
As I mentioned above, there are three phases in this build process:
- We start out installing the Cygwin environment. As described on the Cygwin web site, Cygnus is a Linux-like environment for Windows. This Linux-like environment is required because of the strong Linux legacy of the Mono project.
- The next phase involves installing the latest Mono combined Windows installation
package. As mentioned, this process will build Mono with Mono; therefore, Mono
must be available in order to complete the necessary
- Finally, once Mono for Windows
is installed, it is merely a matter
completing the actual build process using the standard
This article finishes with a call to arms for the Mono community to improve the build and deployment process for Windows.
Requirements for this process:
- Cygwin Linux-like environment for Windows (I used version 1.5.7-cr 0x9e, built on 2004-01-30 19:32, located on cygwin1.dll).
- Internet connection, duh
- 3.6GB of hard drive space between the Cygwin setup files, the Cygwin installation, the Mono source code, exports, and the new build.
1. Getting Started
The first phase of the build process is to install the Cygwin environment. If previous attempts have failed, it is critical that you exorcise these demons from your machine. This is important, because if the Cygwin installer should find the remnants of a previous installation, it will follow the registry keys left and may corrupt the installation. It is always best to start with a clean system.
Note: You can skip this step and proceed to the environment setup if your system does not currently contain Cygwin.
The steps to remove a previous installation of Cygwin are as follows:
- If there is an existing
shortcut on the Windows
desktop, switch to the desktop view. Locate the Cygwin icon, single-click on the shortcut, and press the
Deletesimultaneously. Select Yes from the Confirm File Delete dialog.
- If there is a Cygwin shortcut on the Quick Launch Toolbar, repeat the process from the previous step and delete the shortcut.
- Right-click on the Windows Start button and select Explore All Users. This will open an Explorer session with the current directory as C:\Documents and Settings\All Users\Start Menu.
- Click on the Programs directory.
- Click on the Cygwin
directory in the right-hand
side window of Explorer, and press
Delete. Select Yes from the Confirm File Delete dialog.
- Repeat the previous step for the Cygwin-XFree86 directory, if it exists. Otherwise, proceed to the next step.
- Click on the Start button and select Run.... Enter "explorer c:\" and click OK. Windows should open a new Explorer session with the c:\ as the current directory.
- Click on the cygwin
directory and press
Delete. Select Yes from the Confirm File Delete dialog.
- Click on the Start button and select Run.... Enter "regedit" and click OK.
- Locate the
HKEY_LOCAL_MACHINEkey and expand the key. Locate the
SOFTWAREkey and expand it. Click on the "Cygnus Software" key and press the
These instructions should remove all traces of Cygwin, and you should be ready to begin the setup for the Mono build process.
1.1 Cygwin Environment Setup
The first phase of building
installing Cygwin. As mentioned in the requirements, I recommend the
1.5.7-1 version, built on 2004-01-30. You might be asking, "What is so
special about this particular build of the Cygwin environment?" Well, at
some point, Cygwin began including GNOME components as part of their X
for Windows. The underlying
glib2 that the bundled GNOME/GTK+
uses is incompatible with one of the
REQUIRED compiler flags,
CC="gcc -nno-cygwin". Therefore you can use the newer Cygwin,
but you would have to go through great lengths to remove any of the
GNOME/GTK+ components before you can compile Mono
for Win32 in a way that results in an independent system (independent
of Cygwin after its initial compilation). There is a PDF
available that lists the contents of the
"magic" 1.5.7-1 release. It includes all of the packages and their
respective versions. If you have to use a Cygwin release after 1.5.7-1,
then delete any package that does not
appear in this list.
I will assume that you have the following pre-setup:
- You have a root-level directory to hold the Cygwin installation packages; let's assume it is called C:\Cyg-install.
- Within the
Cyg-install directory is the Cygwin
setup.exeand associated setup.ini.
- Finally, within the Cyg-install directory, you have a sub-directory C:\Cyg-install\releases, containing the 386 assorted package tarballs required for the installation.
The following steps will lead you through the Cygwin installation process:
- Run the Cygwin setup from the Cyg-install directory.
- The setup program will launch the installation process. The setup wizard will first display a splash dialog to start the process. Click the Next button to proceed with the installation.
- On the next screen of the installation wizard, you must choose the installation type. There are three options: Install from Internet, Download from Internet, and Install from Local Directory. Choose Install from Local Directory and click the Next button.
- "Choose Installation Directory" is the next screen of the installation process. In this screen, you will designate the root directory for the Cygwin installation, who the installation is for, and the default text file type. The default root directory should be C:\cygwin, of course assuming that C: is your boot drive. Accept the default directory, the default "All Users" selection, and the default "Unix" text file type and click the Next button.
- The installation wizard will next request the location of the local package directory. If you launched the setup routine from the C:\Cyg-install directory, the default should be that directory. If that is true, click the Next button to accept the default. Note: After clicking Next, the installation wizard will complete a MD5 check to ensure package integrity before installation.
- After the MD5
check, the Select Packages screen should appear. As shown in Figure 1,
notice that the screen
is in the Category view, and the word "Default" is beside each package
selection. Beside the root level category All, there is the word
Default. Click on the word Default and it should change to Install.
This will instruct the
Cygwin installation wizard to install all packages. Click the Next
button to initiate the installation.
Figure 1. Setting up Cygwin
Note: This will take some time, so just keep an eye on the progress bars to verify progress.
- When the
installation completes, the wizard will present one last screen, Create
Icons. Ensure that both options of Create icon on Desktop and Add icon
Start Menu are selected, and click the Finish button.
Note: At this point, the Cygwin installation is complete; however, there are a few more steps to finish the environment setup.
- From either the Quick Launch Toolbar or from the desktop, launch the Cygwin environment. This will create several hidden files in the Cygwin root directory. The files will all start with a "." (period). The exact files created are .bash_profile, .baschrc, and .inputrc.
- Exit the
Cygwin environment by typing "exit" and pressing
- You need to
edit the .bashrc file to add the necessary Mono environment variables,
and the environment variables for Mono CVS access and .NET, if they are not
already in your Windows
PATH. To make these changes inside the Cygwin environment, use the following instructions. (Note: You may encounter difficulty if you attempt to use a Windows text editor to make these changes. It may introduce CR/LF characters into the file instead of the LF characters Cygwin is used to.)
- Re-enter the Cygwin environment.
vi ./.bashrcto edit the file. At this point, you should see the contents of the file and should be able to navigate using the arrow keys.
- Position the cursor at the end of the file by using the down arrow key until the cursor stops at the end of the file.
- Type "i" to insert text
into the file.
Note: It is possible to cut and paste between Windows and the Cygwin environment (even into a
visession). Simply copy the text from Figure 2, and then click on the Cygwin icon in the title bar of the Cygwin window. Select Edit and then select Paste. That should fill in the text. You can also just type it all in; that is, if you like typing.
the text from Figure 2, and press
Escapewhen you are finished.
- Press the ":" (colon) key and you will
viline command prompt.
- Enter "wq" and press
Enter. This will write the file to disk and quit the
vieditor. Note: You need to exit and re-enter Cygwin for these environment variables to become active.
#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
Figure 2: Setting up the environment
- The final step in the environment setup phase
involves setting up the necessary directory structure. Make sure you
are in the Cygwin environment, and enter
mkdir -p /download/tarball/. Also make a sub-directory for the build directory; enter
mkdir -p /download/mono-x.x.x(where
x.x.xrepresents the release number).
- If the Cygwin distribution used in this
phase did not have the Perl XML parser, you need to add it to your Cygwin
environment. To add the parser:
- Download the tarball from SourceForge. Choose your c:\cygwin\download\tarball directory as the download destination directory.
- Once the
download is complete, change directory to the root of Cygwin by typing
cd /and pressing
- From the
tar -xjvf /download/tarball/perl-XML-Parser-2.34-1.tar.bz2and press
Enter. This will uncompress the necessary files and place them in the correct directory locations.
2. Installing Mono
If you already have the latest development version of Mono installed, you can skip this section. If not, then in this second phase you will need to download the combined installer and complete the installation.
- Download the Windows Installer from Mono Latest Development Version and save the file in the directory of your choosing.
- Run the combined installer. The setup wizard will present the welcome screen.
- Click the Next button to proceed. The setup wizard will present the license agreement.
- Select "I accept the agreement" and click the Next button. The setup wizard will present the release notes for the installer.
- Click the Next button and the setup wizard will prompt for the installation location.
- Do not accept
the default suggestion! Enter C:\mono\Mono-1.1.3 instead (see Figure
3 below). This is critical because, for our purposes, spaces in
paths are evil. We will later mount this directory within Cygwin and
use it to create symbolic links. Click the Next button to proceed to the
component selection screen.
Figure 3. Installing Mono
- Verify the component selection; I recommend choosing all components. Click the Next button to proceed.
- Verify the start menu folder Mono 1.1.3 for Windows and click the Next button.
- The next screen of the setup wizard requires you to select the port XSP will use. Accept the default port, 8088, and click the Next button.
- Finally the setup wizard is ready to install Mono, click the Install button. When the installation is complete, the setup wizard will display a screen indicating that the installation complete.
- Click Finish to complete the setup.
Pages: 1, 2