How to compile a .fs file into a .exe?

為{幸葍}努か 提交于 2019-12-22 08:06:03

问题


I do not find a way to compile a simple file (.fs) to a .exe. I tried this example and it does not work:

  1. In the file dolphin.fs:

    let longBeaked = "Delphinus capensis"
    let shortBeaked = "Delphinus delphis"
    let dolphins = [ longBeaked; shortBeaked ]
    printfn "Known Dolphins: %A" dolphins
    
  2. You can now compile this code to an EXE as shown here:

    C:\fsharp> fsc dolphins.fs
    C:\fsharp> dir dolphins.exe
    

But when I do this an error occurs on the ":" from "C:\fsharp"


回答1:


This seems a bit wrong - aside from the fact that you're not supposed to type the first bit (as explained by svick), you probably also need to specify the full path to the F# compiler. If you're using F# that comes with Visual Studio 2010, then you need:

"C:\Program Files (x86)\Microsoft F#\v4.0\Fsc.exe" dolphins.fs

If you're using standalone installation of F#, then you'll need to locate the F# compiler somewhere else (probably in "Program Files (x86)\FSharp-2.0.0.0", but I'm not exactly sure). Also, I'm not sure what is the dir command supposed to do. To execute the compiled application (once it is compiled), you can just type:

doplhins.exe



回答2:


You're not supposed to type the whole line. The C:\fsharp> part represents the command line prompt. You should just type fsc dolhins.fs and then dir dolphins.exe.




回答3:


The error messages sound like you're typing command-prompt commands into F# interactive.

Try opening the "Visual Studio Command Prompt" from your start menu, changing to the right directory, and typing your commands there.

Alternately, create a new F# Application project in Visual Studio, add your .fs file to the project, and build it.



来源:https://stackoverflow.com/questions/7713377/how-to-compile-a-fs-file-into-a-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!