Mono Compilation on a pcDuino

Being a C# .NET developer and a Xamarin developer, it was just a matter of time before I had to have Mono on my pcDuino.    A default package installation of Mono on any ARM (ARMhf) device (like the pcDuino with it’s A20 processor) at this moment is unfortunately not possible as it’s not available yet.  However luckily Mono can be compiled directly on the pcDuino.   I’ll share my exploration of building Mono 3.12.0 here.

Attempting to install the current Mono packages on a system with an ARMhf processor will currently yield the following unfriendly error messages:

sudo apt-get install mono-devel
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
mono-devel : Depends: mono-runtime (>= 2.10.1) but it is not going to be installed
Depends: libmono-cecil-private-cil (>= 3.12.0) but it is not going to be installed
Depends: libmono-cecil-private-cil (< 3.12.1) but it is not going to be installed
Depends: libmono-codecontracts4.0-cil (>= 1.0) but it is not going to be installed
Depends: libmono-compilerservices-symbolwriter4.0-cil (>= 3.6.0) but it is not going to be installed
Depends: libmono-corlib2.0-cil (>= 3.2.8) but it is not going to be installed
Depends: libmono-corlib4.5-cil (>= 3.12.0) but it is not going to be installed
Depends: libmono-peapi2.0a-cil (>= 3.2.8) but it is not going to be installed
Depends: libmono-peapi4.0a-cil (>= 3.2.8) but it is not going to be installed
Depends: libmono-relaxng4.0-cil (>= 2.10.1) but it is not going to be installed
Depends: libmono-security2.0-cil (>= 3.0.6) but it is not going to be installed
Depends: libmono-security4.0-cil (>= 3.0.6) but it is not going to be installed
Depends: libmono-system-componentmodel-composition4.0-cil (>= 3.0.6) but it is not going to be installed
Depends: libmono-system-componentmodel-dataannotations4.0-cil (>= 3.2.3) but it is not going to be installed
Depends: libmono-system-configuration-install4.0-cil (>= 1.0) but it is not going to be installed
Depends: libmono-system-configuration4.0-cil (>= 1.0) but it is not going to be installed
Depends: libmono-system-core4.0-cil (>= 3.2.8) but it is not going to be installed
Depends: libmono-system-data-linq4.0-cil (>= 1.0) but it is not going to be installed
Depends: libmono-system-data2.0-cil (>= 3.12.0) but it is not going to be installed
Depends: libmono-system-data4.0-cil (>= 3.12.0) but it is not going to be installed
Depends: libmono-system-numerics4.0-cil (>= 1.0) but it is not going to be installed
Depends: libmono-system-runtime-serialization4.0-cil (>= 1.0) but it is not going to be installed
Depends: libmono-system-runtime4.0-cil (>= 2.10.1) but it is not going to be installed
Depends: libmono-system-security4.0-cil (>= 1.0) but it is not going to be installed
Depends: libmono-system-servicemodel4.0a-cil (>= 3.2.3) but it is not going to be installed
Depends: libmono-system-web-services4.0-cil (>= 1.0) but it is not going to be installed
Depends: libmono-system-web2.0-cil (>= 2.10.3) but it is not going to be installed
Depends: libmono-system-xml-linq4.0-cil (>= 3.0.6) but it is not going to be installed
Depends: libmono-system-xml4.0-cil (>= 3.12.0) but it is not going to be installed
Depends: libmono-system2.0-cil (>= 3.12.0) but it is not going to be installed
Depends: libmono-system4.0-cil (>= 3.12.0) but it is not going to be installed
Depends: libmono2.0-cil (>= 3.6.0) but it is not going to be installed
Depends: mono-mcs (= 3.12.0-0xamarin3) but it is not going to be installed
Depends: mono-gac (= 3.12.0-0xamarin3) but it is not going to be installed
Depends: mono-xbuild (= 3.12.0-0xamarin3) but it is not going to be installed
Depends: libmono-cil-dev (= 3.12.0-0xamarin3) but it is not going to be installed
Depends: libmono-2.0-dev (>= 3.12.0-0xamarin3) but 3.2.8+dfsg-4ubuntu1 is to be installed
Recommends: mono-csharp-shell but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

 

To solve this problem we will make our own ARMhf targeted build. Let’s start by finding a USB memory stick or a SD card with sufficient space.   The Mono source repository is quite large and it occupies about two gigabytes of storage. I would suggest a size of four gigabytes or more (I used an eight gigabyte module myself).  Make sure it’s formatted to the Ext file system.  FAT32 will not work for compilation.  I wasted a good couple of hours with error messages caused simply by the chaos caused using the wrong file system.

 

To figure out what to do, I referred to the official Mono documentation for the installation steps I list below.   These compilation instructions can also be found here on the Mono site:  http://www.mono-project.com/docs/compiling-mono/linux/

 

Let’s first make sure we have the tools available to build Mono.

 

$ apt-get install git autoconf libtool automake build-essential gettext

 

Clone the Mono source code from the git repository.

 

$ cd /media/[path to your external media]
$ git clone git://github.com/mono/mono.git

 

The cloning of the Git repository can take a while depending on the internet connection.   The size of the repository is just under two gigabytes so try to be patient.

 

The entire process of compilation will take about five hours on the pcDuino, so best to do this overnight..

$ cd mono
$ git checkout mono-3.12.0-branch
$ git submodule init
$ git submodule update --recursive
$ git submodule

$ ./autogen.sh --prefix=/usr/local --with-sgen=yes --with-large-heap=yes --with-xen_opt=no --enable-parallel-mark --with-libgdiplus=/usr/local/lib
$ make get-monolite-latest
$ make EXTERNAL_MCS="${PWD}/mcs/class/lib/monolite/gmcs.exe"
$ make

Build in progress!

 

monocompiling

 

Compiling is complete!  So to conclude we will install the build locally.

$ sudo make install

 

Once installed check the Mono version.

$ mono --version

 

If you are seeing the message below, congratulations you have successfully built Mono 3.12 on your device!

Mono JIT compiler version 3.12.0 (mono-3.12.0-branch/501f5a9 Mon Feb 2 12:41:29 UTC 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: normal
Notifications: epoll
Architecture: armel,vfp+hard
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen

 

For the non-adventurous or if you are just needing to save time, you can download my Mono-3.12.0 package here:  http://1drv.ms/1zvLtgN

 

Now that we have mono installed we can explore some pcDuino .net (c#) related topics in future posts.

apead

I am a Xamarin Most Valueable Professional (MVP), Microsoft Developer Technologies MVP, Microsoft Internet of Things MVP, Microsoft Azure MVP, Architect, Software Developer, Organizer and Sponsor of the CPTMSDUG, JHBMSDUG and DBNMSDUG User Groups and father of 2.