简体   繁体   中英

Running a compiled F# program with Mono on Linux

I installed mono and fsharp on my CentOS box through

$ sudo yum install mono-complete fsharp

and installed dotnet things following

https://docs.microsoft.com/en-us/dotnet/core/install/linux-package-manager-centos7

I compiled my Hello World F# program with

$ fsharpc Program.fs

Now, when I try to run this with mono:

$ mono Program.exe 
Can't find custom attr constructor image: /home/gbuday/ion/Program.exe mtoken: 0x0a000005 due to: Could not load file or assembly 'FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

When I run this with

$ dotnet run Program.exe 
Hello World from F#!

it runs smoothly. It is not clear how mono and dotnet relates in this setting.

Will I be able to run my compiled F# code with mono? What do I need for it?

The issue that you're seeing is that mono is only compatible with an older F# language and core library, and since you don't have that older version, it blows up at runtime.

Mono is only necessary if you are using Xamarin to build mobile apps in F# today. If you're doing anything else on a Linux machine I recommend using .NET Core and the .NET CLI for everything. I recommend following this guide as a start: https://docs.microsoft.com/dotnet/fsharp/get-started/get-started-command-line

You can do things in a slightly simpler way (no solution file, just a single project) as well, but the linked guide will set up a file structure that is common to see in codebases in the wild.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM