Saturday, 10 November 2012

Trying to get F# working on the Raspberry Pi


The Raspberry Pi uses an older ARMv6 core which is not well supported by modern software. In particular, Mono's JIT apparently doesn't support the hardware-accelerated floating point instructions used by that version of the ARM instruction set. The solution is apparently to use the soft-float version of Raspian that emulates floating point instructions in software (which will be extremely slow). However, trying to compile the current version of the F# sources on Github using the stock Mono (2.10.8) fails with the following null reference exception from within the F# compiler:

error FS0193: internal error: Object reference not set to an instance of an object

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Collections.FSharpList`1[System.String],System.String].InvokeFast[CcuThunk] (Microsoft.FSharp.Core.FSharpFunc`2 func, Microsoft.FSharp.Collections.FSharpList`1 arg1, System.String arg2) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Env.mkTcGlobals (Boolean compilingFslib, Microsoft.FSharp.Compiler.CcuThunk sysCcu, Microsoft.FSharp.Compiler.AbstractIL.ILGlobals ilg, Microsoft.FSharp.Compiler.CcuThunk fslibCcu, System.String directoryToResolveRelativePaths, Boolean mlCompatibility, Boolean using40environment, Boolean indirectCallArrayMethods, Boolean isInteractive, Microsoft.FSharp.Core.FSharpFunc`2 getTypeCcu) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Build+TcImports.BuildFrameworkTcImports (Microsoft.FSharp.Compiler.TcConfigProvider tcConfigP, Microsoft.FSharp.Collections.FSharpList`1 frameworkDLLs, Microsoft.FSharp.Collections.FSharpList`1 nonFrameworkDLLs) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Driver.getTcImportsFromCommandLine$cont@322 (Exiter exiter, Microsoft.FSharp.Core.FSharpOption`1 displayPSTypeProviderSecurityDialogBlockingUI, Microsoft.FSharp.Compiler.LexResourceManager lexResourceManager, Microsoft.FSharp.Collections.FSharpList`1 sourceFiles, System.String assemblyName, Microsoft.FSharp.Compiler.TcConfig tcConfig, Microsoft.FSharp.Compiler.ErrorLogger errorLogger, Microsoft.FSharp.Core.Unit unitVar) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Driver.getTcImportsFromCommandLine (Microsoft.FSharp.Core.FSharpOption`1 displayPSTypeProviderSecurityDialogBlockingUI, System.String[] argv, System.String defaultFSharpBinariesDir, System.String directoryBuildingFrom, Microsoft.FSharp.Core.FSharpOption`1 lcidFromCodePage, Microsoft.FSharp.Core.FSharpFunc`2 setProcessThreadLocals, Microsoft.FSharp.Core.FSharpFunc`2 displayBannerIfNeeded, Boolean optimizeForMemory, Exiter exiter, Microsoft.FSharp.Core.FSharpFunc`2 createErrorLogger) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Driver.main1 (System.String[] argv, Boolean bannerAlreadyPrinted, Exiter exiter, Microsoft.FSharp.Core.FSharpFunc`2 createErrorLogger) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Driver.mainCompile (System.String[] argv, Boolean bannerAlreadyPrinted, Exiter exiter, Microsoft.FSharp.Core.FSharpFunc`2 createErrorLogger) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.CommandLineMain+Driver.main (System.String[] argv) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.CommandLineMain.main (System.String[] argv) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Collections.FSharpList`1[System.String],System.String].InvokeFast[CcuThunk] (Microsoft.FSharp.Core.FSharpFunc`2 func, Microsoft.FSharp.Collections.FSharpList`1 arg1, System.String arg2) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Env.mkTcGlobals (Boolean compilingFslib, Microsoft.FSharp.Compiler.CcuThunk sysCcu, Microsoft.FSharp.Compiler.AbstractIL.ILGlobals ilg, Microsoft.FSharp.Compiler.CcuThunk fslibCcu, System.String directoryToResolveRelativePaths, Boolean mlCompatibility, Boolean using40environment, Boolean indirectCallArrayMethods, Boolean isInteractive, Microsoft.FSharp.Core.FSharpFunc`2 getTypeCcu) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Build+TcImports.BuildFrameworkTcImports (Microsoft.FSharp.Compiler.TcConfigProvider tcConfigP, Microsoft.FSharp.Collections.FSharpList`1 frameworkDLLs, Microsoft.FSharp.Collections.FSharpList`1 nonFrameworkDLLs) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Driver.getTcImportsFromCommandLine$cont@322 (Exiter exiter, Microsoft.FSharp.Core.FSharpOption`1 displayPSTypeProviderSecurityDialogBlockingUI, Microsoft.FSharp.Compiler.LexResourceManager lexResourceManager, Microsoft.FSharp.Collections.FSharpList`1 sourceFiles, System.String assemblyName, Microsoft.FSharp.Compiler.TcConfig tcConfig, Microsoft.FSharp.Compiler.ErrorLogger errorLogger, Microsoft.FSharp.Core.Unit unitVar) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Driver.getTcImportsFromCommandLine (Microsoft.FSharp.Core.FSharpOption`1 displayPSTypeProviderSecurityDialogBlockingUI, System.String[] argv, System.String defaultFSharpBinariesDir, System.String directoryBuildingFrom, Microsoft.FSharp.Core.FSharpOption`1 lcidFromCodePage, Microsoft.FSharp.Core.FSharpFunc`2 setProcessThreadLocals, Microsoft.FSharp.Core.FSharpFunc`2 displayBannerIfNeeded, Boolean optimizeForMemory, Exiter exiter, Microsoft.FSharp.Core.FSharpFunc`2 createErrorLogger) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Driver.main1 (System.String[] argv, Boolean bannerAlreadyPrinted, Exiter exiter, Microsoft.FSharp.Core.FSharpFunc`2 createErrorLogger) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.Driver.mainCompile (System.String[] argv, Boolean bannerAlreadyPrinted, Exiter exiter, Microsoft.FSharp.Core.FSharpFunc`2 createErrorLogger) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.CommandLineMain+Driver.main (System.String[] argv) [0x00000] in <filename unknown>:0
  at Microsoft.FSharp.Compiler.CommandLineMain.main (System.String[] argv) [0x00000] in <filename unknown>:0

We'll keep trying...

3 comments:

Unknown said...

I get exactly the same error with a 3.0.3 mono build... And the fsharp code from github doesn't compile on the raspberry. I keep getting a Sigsegv error

Nicolas said...

does that work on other mono versions ?

Art said...

http://fsharpnews.blogspot.com/2013/01/f-on-linux.html
Sunday, 20 January 2013
F# on Linux
The F#.NET Journal just published an article by Martin Trojer about Linux:
"The F# software foundation was recently formed to help diversify the F# programming language beyond the Microsoft ecosystem. This article is the first in a series looking at the use of F# on non-Microsoft operating systems, specifically Linux on the desktop and on a Raspberry Pi..."
To read this article and more, subscribe to The F#.NET Journal today!
Posted by Jon Harrop at 23:37
Labels: linux, raspberry pi