Building Mono on a Raspberry Pi (Hard Float)

The cool thing about the Raspberry Pi is that it is really really cheap and really really popular.

Until recently the worst thing about the Raspberry Pi has been the lack of hardfp version of Mono, leaving us .NET developers with 2 options:

  1. Learn something new (like Scala)
  2. Run the softfp Mono on the older Debian Squeezy Linux Distro

Now I know C# developers will be balking at the idea of #1, which only leaves #2.

Until now…….

Now Mono supports hardfp and a recent Mono (3.2.7), which is Good News(tm) as that means it supports the sgen GC as we’ll has the hardware floating point extensions on the ARM6 on the Pi.

Instructions are available here, but I hit a couple of small wrinkles on a fresh Raspbian install, so for my benefit and yours:

Step by Step

A couple of people have commented about how they needed to sudo some of these things (I didn’t need to – don’t know why), but remember, when in doubt sudo

  1. Ensure you have 2GB+ free on your SD card and a lot of time to spare
  2. Launch a terminal window/ssh into your Pi
  3. sudo apt-get update
  4. sudo apt-get install mono-complete
  5. sudo apt-get install automake
  6. sudo apt-get install libtool
  7. git clone git://github.com/mono/mono.git
  8. cd mono
  9. ./autogen.sh –prefix=/usr/local –enable-nls=no 
  10. Note the above step reads two dashes before prefix and enable-nls. Thanks crazy fonts (and eagle eyed readers)
  11. sudo make
  12. Wait a long time (6 hours +)
  13. Ignore the errors and hope they don’t mean anything
  14. sudo make install
  15. Wait some more
  16. Ignore the errors and hope they don’t mean anything
  17. PROFIT!

Now type mono –version and hopefully see this:

pi@raspberrypi ~/mono $ mono --version
Mono Runtime Engine version 3.2.7 (master/e94da6d Tue Dec 10 00:31:36 UTC 2013)
Copyright (C) 2002-2013 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 directions on how to be able to build and run Winforms apps see this excellent post here

Advertisements

About thedo666

Software developer trying to learn a new language - English!
This entry was posted in C#, Mono, Uncategorized. Bookmark the permalink.

29 Responses to Building Mono on a Raspberry Pi (Hard Float)

  1. AlhimiK-FlameR says:

    Thanks a lot for your guide.

    on step 9
    maybe need ? else I got errors

  2. AlhimiK-FlameR says:

    Thanks a lot for your guide.

    on step 9 [./autogen.sh –prefix=/usr/local –enable-nls=no]
    maybe need [./autogen.sh –enable-nls=no] ? else I got errors

  3. James says:

    Thank you for the guide but just to add – on step 9 it appears as “-” however I believe this is meant to be “–” instead.

  4. brianpclab says:

    i had to do sudo make install

  5. brianpclab says:

    Winform apps did not work after the install because it could not find libgdiplus had to perform the following from the mono folder
    git clone git://github.com/mono/libgdiplus
    cd libgdiplus
    ./autogen.sh –prefix=/usr/local
    sudo make
    sudo make install
    After all of that about 1 hour winform apps work fine.

    • thedo666 says:

      Awesome thanks for the addition. I’ve only used for CLI apps as I’m just using ssh to he pi, but I’ll be sure to add a link in the article to your comment 😉

  6. MrCC says:

    Any chance that you or someone else who already did the compilation provide the binaries so that not everyone who wants a non-broken mono version has to go through the compile grind? Would be very thankful.

  7. Markus says:

    Thanks for the guide! Seems like it only works with an en-us UTF8 locale, though.
    After I switched to en-us UTF8 and rebooted the pi, everything compiled.
    Now installing and testing 🙂

    • Markus says:

      What a PITA.

      After
      sudo make install
      now a simple WinForms “HelloWorld.exe” exits with an exception stating that libgdiplus.so cannot be found. I’m giving up. Hopefully someone soon will come up with something I simply can sudo apt-get install … :/

      • thedo666 says:

        While I completely agree its not ideal that theres not an out-of-box solution yet, it *does* feel like the point of the pi is to enable this kind of “tactile” play. I’ve built more open source solutions on my pi than on my Windows or Mac boxes, and theres a definite feeling of achievement when it works. But sometimes you *really* have to work to get that feeling!

      • MrCC says:

        @thedo666: I beg to differ. Because that notion would imply that you think releasing a *completely broken, non-working (as in: calculates things wrong) mono version on the repository* (2.10.XX) without any mention of its state was also with the intention of nurturing someone’s sense of accomplishment once you discover that state and take steps to remedy it.

        The sort of “tactile play” as you call it always should be *optional*, and never mandatory (as in the case of the mono binaries).

      • thedo666 says:

        I absolutely agree that its a massive fail that the “out-of-box” solution isn’t just damaged but entirely broken. It plain and simply shouldn’t be there until its working and stable.

        I did state at the top of the post that there were 2 options until now:

        Learn something new (like Scala)
        Run the softfp Mono on the older Debian Squeezy Linux Distro

        It sounds like you don’t want to do option 1, you don’t want to build it (which I guess counts as option 3), so that leaves option 2.

  8. brianpclab says:

    had no problem getting this to work on Raspbian but always got a disk error proc/sys/kernel/hung_task_timeout_secs scsi_eh_0 when I tried Arch Linux from the raspberry site. Disk error always occurred during the make at the same place. Gave up after three days and when back to Raspbian

  9. Pingback: MonoGame บน Raspberry Pi (ภาคทดลอง) | Raspberry Pi Thailand

  10. Tom says:

    I am successful in getting the package installed. confirmed by mono -V
    However it does not create the mod_mono.conf file that is needed for the Apache2.conf file.
    I checked the entire raspi and can not find this file anyplace.

    What can I do?

  11. I used no-no utf8, should that matter?

    Having some problems with mscorlib.dll not found in mono/2.0, but can see it is present in mono/4.0. Tried numerous ways to override runtime, but it seems to default to 2.0.50727 for some reason?

    • thedo666 says:

      Cant say for sure as it defaulted to the correct runtime for me after I built it, so I gather the defaults for encoding in the default UK locale.

      Looking at Markus reply it has to be en-US, but I havent had any reason to rebuild in other locales.

  12. Anonymous says:

    After compiling are there files that can be deleted? like the sources or something like that?
    BTW when will this version be put in the apt repository? it would be great not to compile the entire library. Thanks in advance

  13. All the instructions after #6 are unnecessary. All I did was install the Mono Debian packages according to instructions 1-6, and then I got this:

    mono –version
    Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4+rpi1)
    Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. http://www.mono-project.com
    TLS: __thread
    SIGSEGV: normal
    Notifications: epoll
    Architecture: armel,vfp+hard
    Disabled: none
    Misc: softdebug
    LLVM: supported, not enabled.
    GC: sgen

    Didn’t have to compile anything, so it looks like the currently available packages have everything needed.

  14. dodgy_coder says:

    Thanks for this, however as Marquis de Sadé pointed out, you don’t need to recompile Mono on Raspbian anymore – the hard float package is supported now via just “sudo apt-get install mono-complete”. You don’t even need 2GB+ free space – it takes up less than 200mb. I used the offical raspbian image from 2014-06-20.

    Here’s a test application to check if hard float is working or not …

    // mono test app
    // compile: dmcs HelloWorld.cs
    // run: mono HelloWorld.exe
    using System;
    public class HelloWorld
    {
    public static void Main(string[] args)
    {
    // The correct answer to this is 1.
    // If it outputs 0 then its running Raspbian (ARM hard float) and is broken…
    // Run the Debian Wheezy (soft float) distro instead.
    Console.WriteLine(“Floor(1.5): ” + System.Math.Floor(1.5));
    }
    }

    • Jonathan says:

      Thanks for this simple test. In case any other noobs try to copy & paste this code onto the raspberry pi, the quotes in “Floor(1.5): ” have to be straight quotes, not angled quotes. Execute this with: mcs float-test.cs
      Wait for it to compile, then execute: mono float-test.exe

  15. Michael says:

    For fellow Arch Linux users on Raspberry Pi, it fixed it when I ran the following configure statement:

    ./configure –prefix=/usr/mono –with-libgdiplus=installed –with-moonlight=no
    http://mono.1490590.n4.nabble.com/The-assembly-mscorlib-dll-was-not-found-or-could-not-be-loaded-td3165401.html

    Also, for some reason the version of mono I had from “pacman -S mono” was not in the path, so I had to make sure I was using v3.4x when I typed “mono -V”. I could have changed the path or what I did, since the version of Mono that was in the path was worthless, I just moved both mono and gmcs to the path so those were called.

  16. Pingback: What can C# be used for? - Marketing & PR - Infragistics.com Blog

  17. Pingback: Mono su Arietta | hthings

  18. toneuk says:

    Thanks for posting this, it has helped me out when testing out vNext on a Raspberry Pi. As others have said, a full compile is no longer necessary, however, it is if you want to run vNext, because it relies on mono 3.4.1 or later.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s