A Mutable Log

A blog by Devendra Tewari


Project maintained by tewarid Hosted on GitHub Pages — Theme by mattgraham

Mono .NET runtime on Raspberry Pi with Buildroot

Mono is a popular way to run .NET applications on platforms other than Windows. In this post I’ll show how to build and copy Mono onto a Raspberry Pi, with Buildroot.

Obtain source code for Mono

Let’s start by obtaining Mono from GitHub. I suggest using a folder outside of Buildroot. Later, we’ll prepare Buildroot to fetch the source code from this folder.

git clone https://github.com/mono/mono.git

Let’s head into the cloned repo. We’ll need to switch to a different branch. After much trial and error I’ve discovered that branch mono-3.6.0-branch builds without any error

cd mono
git checkout mono-3.6.0-branch

Create a package for Mono in Buildroot

We’ll create a new package called mono in Buildroot, that will fetch the source code for Mono from the cloned repo, and prepare and build it.

The location of source code for the mono package needs to be specified in file local.mk in Buildroot’s root folder

MONO_OVERRIDE_SRCDIR = /home/parallels/mono/

Add a new package called mono to package/Config.in. I’ve added it under menu “Interpreter languages and scripting”, but you can choose another menu

menu "Interpreter languages and scripting"
        source "package/mono/Config.in"

We’ll create a new folder called mono under folder package, and make a configuration file called Config.in

mkdir package/mono
vi package/mono/Config.in

Here’s the content of Config.in

config BR2_PACKAGE_MONO
    bool "mono"
    help
      Sponsored by Xamarin, Mono is an open source implementation of Microsoft's .NET Framework based on the ECMA standards for C# and the Common Language Runtime.

      https://github.com/mono/mono

Next, we’ll tell Buildroot how to build the mono package

vi package/mono/mono.mk

Here’s the content for package/mono/mono.mk

################################################################################
#
---
layout: default
title: mono
tags:
---
# mono
#
################################################################################

MONO_AUTORECONF = YES
MONO_DEPENDENCIES = libglib2

$(eval $(autotools-package))

Configure Buildroot and perform the build

Now that package mono has been created, select it by invoking the configuration menu

make menuconfig

You’ll also need to switch to glibc under Toolchain. Build with uClibc fails with

os_dep.c:3990:23: execinfo.h: No such file or directory

glibc

Now, all that’s left to do is to perform the build

make clean
make

After the build, prepare the SD card. Mono’s build does not copy .NET core libraries to the target filesystem. You’ll need to copy those manually, like so

sudo cp -R output/build/mono-custom/mcs/class/lib/basic/* /media/parallels/System/usr/lib/mono/2.0

If you forget to do that, .NET applications will fail with a message such as

The assembly mscorlib.dll was not found or could not be loaded.
It should have been installed in the `/usr/lib/mono/2.0/mscorlib.dll' directory.

Notes

Builds on branches master and mono-3.12.0-branch fail with

mono/mini/Makefile.am:86: error: JIT_SUPPORTED does not appear in AM_CONDITIONAL
mono/mini/Makefile.am:722: error: JIT_SUPPORTED does not appear in AM_CONDITIONAL
mono/unit-tests/Makefile.am:7: warning: variable 'TEST_LDFLAGS' is defined but no program or
mono/unit-tests/Makefile.am:7: library has 'TEST' as canonical name (possible typo)
autoreconf: /home/devendra/buildroot-2014.08/output/host/usr/bin/automake failed with exit status: 1

Builds on branches mono-3.8.0-branch and mono-3.10.0-branch fail with link time error

mini.c:(.text+0x7878): undefined reference to `mono_cross_helpers_run'