Reputation: 10204
I have a hello world program in F#.
open System
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code%
On an Mac OS, I can compile it with "fsharpc", which generates two files
FSharp.Core.dll hello.exe
The EXE file certainly looks strange on a Mac. But how can I execute it from the command line, without using a project structure (because it seems an overkill) like what is explained here: https://dotnet.microsoft.com/learn/languages/fsharp-hello-world-tutorial/create
Actually if I run "dotnet hello.exe", I get this error:
A fatal error was encountered. The library 'libhostpolicy.dylib' required to execute the application was not found in '/Users/zell/hello/'. Failed to run as a self-contained app. If this should be a framework-dependent app, add the /Users/zell/hello/hello.runtimeconfig.json file specifying the appropriate framework.
Upvotes: 1
Views: 277
Reputation: 6949
By trial and error, I found to run my new .exe
file, I needed a .runtimeconfig.json
file in the same folder with same without-the-extension-name, i.e. hello.runtimeconfig.json
:
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}
Then dotnet hello.exe
will work.
Upvotes: 0
Reputation: 5005
You can create and build/run F# apps like so:
dotnet new console -lang F# -o SomeDirectory && cd SomeDirectory
dotnet run
Building it without running is:
dotnet build
You can see a reference for all commands here: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet
You appear to have Mono installed, which is where fsharpc
comes from. I wouldn't recommend using that unless you are doing mobile development with Xamarin, which currently requires Mono.
Upvotes: 2