"... and no one shall work for money, and no one shall work for fame; But each for the joy of the working, and each, in his separate star, shall draw the thing as he sees it, for the god of things as they are"

-Kipling

 

Installing Mono and C# on the Beaglebone Black

Summary

This page describes how to install C# and Mono on the Beaglebone Black. There are a number of pre-requisite actions which are required in order to have a successful installation. This page is one part of a series of web pages which describe how to install C# and Mono on the Beaglebone Black and also how to setup a useful remote compilation and debugging toolchain for it.

Installing Mono on the Beaglebone Black

Note: Before you continue with any of the steps on this page be aware you need to install Mono on the armhf version of the Debian operating system. Mono will not install (at least I could never get it to work) on the standard armel package that ships with the Beaglebone Black. If you have not got the armhf package installed you will need to complete the earlier steps first.

Assuming you have armhf installed and networking configured with full Internet access on your Beaglebone Black, you can install Mono by issuing the following commands (as root). If you wish, instead of prefacing each command with sudo, you can change into the root user by issuing the sudo -s command.

First let's make sure all packages are fully up-to-date and you have the latest build tools...

sudo apt-get update
sudo apt-get install build-essential automake checkinstall intltool git

For me, the above commands worked with no visible errors and the time taken was about five minutes. Once that is done, we need to install the Mono runtime - but we have to make sure we get the correct mono version. By default, if we try an apt-get install mono-runtime command, we will get an older Mono version which has a bug which makes remote debugging impossible. We need to make sure we add the latest Mono Project GPG signing key and the package repository to our system. This is done by issuing the following commands (taken from the mono-project page).

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update

The above commands took very little time on my system. Now we can proceed with the install of the Mono runtime.

sudo apt-get install mono-runtime

The above command worked with no errors and one warning. The elapsed time was about a minute. Now we can install the Mono package.

sudo apt-get install mono-complete git automake libtool

The above commands worked with no errors and the runtime was about 5 minutes.

At this point the Mono .NET runtime should be installed. You can test this by issuing the command mono -V. If installed correctly, you should see the version display as shown below

debian@beaglebone:~$ mono -V
Mono JIT compiler version 4.0.1 (tarball Tue May 12 17:22:22 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
debian@beaglebone:~$ 

You can also type the command mcs --about on the command line to see if Mono C# compiler is there. On my system the command returned the following...

debian@beaglebone:~$ mcs --about
The Mono C# compiler is Copyright 2001-2011, Novell, Inc.

The compiler source code is released under the terms of the
MIT X11 or GNU GPL licenses

For more information on Mono, visit the project Web site
   http://www.mono-project.com

The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath, Atushi Enomoto

Now we need to test things out. Below is some simple "Hello World" code. You can use the simple nano editor to create this (issue the command nano helloworld.cs) by copying the text below and pasting it in.

using System;
namespace Hello {
	class HelloWorld {
		public static void Main(string[] args) {
			Console.WriteLine("Hello World!");
		}
	}
}

I compiled the above code with the command mcs helloworld.cs and then ran it with the command mono helloworld.exe. Note that you can also issue the rather simpler command ./helloworld.exe and the operating system will figure out that it is a .NET executable and automatically invoke Mono for you. On my system all of the above code executed perfectly.

A Note on Mono Versions

As was mentioned previously, the Mono version you probably want is the one pointed to by the Mono Project GPG signing key and the package repository command above. If you omit this step you may install a much older version of Mono which is the default for the 3.8 Linux kernel. For example, instead of the 4.0.1 version information above, the mono -V command will return something like...

Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-5ubuntu2)
...and if, as discussed in later steps, you try to implement remote debugging you will run straight into this bug . It's now been fixed but, simply put, remote debugging is not possible on earlier versions of Mono.

A Remote Development Tool Chain for the Beaglebone Black

If you have followed the steps above you will have seen that editing .cs files on the Beaglebone Black is possible but perhaps not too user friendly. There is a nice GUI development environment for Mono called MonoDevelop. The next step discusses how to install MonoDevelop on a remote Ubuntu Linux box and to configure it so that you can compile on that platform and the resulting exe file is transported to the Beaglebone Black for execution.

License

The contents of this web page are provided "as is" without any warranty of any kind and without any claim to accuracy. Please be aware that the information provided may be out-of-date, incomplete, erroneous or simply unsuitable for your purposes. Any use you make of the information is entirely at your discretion and any consequences of that use are entirely your responsibility. All source code is provided under the terms of the MIT License.