Building mono from source

From LSDevLinux
Jump to: navigation, search

We use a custom version of mono that has a number of patches applied relative to the official, "upstream" mono releases. We have forks of the various git repos involved, and a branch named develop in each of these. This branch is based on an official upstream release with additional commits for each of our patches.


On Ubuntu or Debian Linux

$ sudo apt-get install gnulib mono-devel mono-mcs libgif-dev libjpeg-dev libtiff4-dev libexif-dev git quilt

And of course to build the package you'll also need:

$ sudo apt-get install devscripts cdbs

On Mac

$ sudo port install git getopt autoconf automake libtool bison giflib jpeg libpng tiff

Note: port is the MacPorts package management command. For further information, see Build FieldWorks for Mac.

Check out sources

Note: If you are developing FieldWorks, you may already have the mono repositories checked out at ~/fwrepo/mono.

You'll need clones of a number of git repositories. The recommended directory layout is to have a single parent directory called mono-sil with the clones as subdirectories:

  • mono-sil
    • gtk-sharp
    • libgdiplus
    • mono
    • mono-basic
    • mono-calgary

The directory and clones can be created using the following commands:

mkdir mono-sil
cd mono-sil
for R in gtk-sharp libgdiplus mono mono-basic mono-calgary; do
    git clone$R.git

The mono repository is fairly large, so this will take a while, especially on slower internet connections.

Build and install

Building mono is done with the script in mono-calgary. Ensure you are in the mono-sil directory (or ~/fwrepo/mono), and then run:


This uses the sudo command internally (to gain permission to install to /opt/mono-sil) and so will ask for your password at various points.

Mono will be installed to MONO_PREFIX, which may default to /opt/mono-sil, so if you want to use /opt/mono5-sil or similar, make sure to set MONO_PREFIX before running

If there are build problems it may help to "clean" the mono subdirectory:

(cd mono && git clean -dxf)

Note that the Linux binfmt system that allows you to execute interpreted programs without specifying the interpreter on the command line (eg by typing just application.exe) will still use /usr/bin/mono unless you reconfigure it.

Build Mono 4

The develop branches of the repositories is not for mono4. To build mono4 on a FW Dev vagrant machine, run commands such as the following to checkout the release/mono4-sil branches, build and install mono4 to MONO_PREFIX. (And hopefully not error with Assertion at local-propagation.c:330, condition `ins->opcode > MONO_CEE_LAST' not met)

 cd ~/fwrepo/mono
 for DIR in *; do cd $DIR && git checkout release/mono4-sil && cd -; done
 MONO_PREFIX=/opt/mono4-sil-fromsrc mono-calgary/

On Mac

Some environment variables need to be set in order for the build of libgdiplus to find the MacPorts libraries it needs. Unfortunately, when these variables are set the builds of the other repos fail. The solution is to build in two stages, each time restricting the build to a subset of the repos. This is done by passing the name the repo(s) to the build script. You should have some variables set permanently in ~/.profile, but others are set temporarily just for building libgdiplus. The complete sequence of commands is as follows:

export CPATH=/opt/local/include
export LIBRARY_PATH=/opt/local/lib
mono-calgary/ libgdiplus
unset CPATH
mono-calgary/ gtk-sharp mono mono-basic

gtk-sharp and mono-basic aren't needed for some Mac programs (eg WeSay) and so can optionally be omitted from the list of repos in the second step above.


Updating is done by pulling the latest changes in each repo and rebuilding. From the mono-sil directory:

for R in gtk-sharp libgdiplus mono mono-basic mono-calgary; do
    (cd $R && git pull)

Debug mono without building

You can run an application using mono as installed from packages, but debug mono using local source code (even though that local source code was not used to build the mono being run).

To do this on an FW Dev vagrant, run:

 sudo mkdir /build
 sudo ln -s ~/fwrepo/mono/mono /build/mono4-sil-4.6.1

Then in Visual Studio Code you can break in mono code such as in ~/fwrepo/mono/mono/mcs/class.