[英]Compiling Haskell (.hs) in windows to a exe
Is it possible to compile a set of .hs
haskell files into a exe in windows?是否可以将一组
.hs
haskell文件编译成 windows 中的 exe? .hs
-> .exe
.hs
-> .exe
Absolutely.绝对地。 Install the Haskell Platform , which gives you GHC , a state-of-the-art compiler for Haskell.
安装Haskell 平台,它为您提供GHC ,这是 Haskell 的最先进的编译器。
By default it compiles to executables, and it works the same on Linux or Windows.默认情况下,它编译为可执行文件,并且在 Linux 或 Windows 上的工作方式相同。 Eg
例如
Given a file:给定一个文件:
$ cat A.hs
main = print "hello, world"
Compile it with GHC:用 GHC 编译它:
$ ghc --make A.hs
[1 of 1] Compiling Main ( A.hs, A.o )
Linking A.exe ...
Which you can now run:您现在可以运行:
$ ./A.exe
"hello, world"
Note, this was under Cygwin.注意,这是在 Cygwin 下。 But the same holds for native Windows:
但同样适用于原生 Windows:
C:\temp>ghc --make A.hs
[1 of 1] Compiling Main ( A.hs, A.o )
Linking A.exe ...
C:\temp>A.exe
"hello, world"
For people who never compiled anything at all, it also might be useful to know that "C:\temp>" in the example by Don Stewart points to the folder in which.hs should be.对于从未编译过任何东西的人来说,知道 Don Stewart 示例中的“C:\temp>”指向应包含.hs 的文件夹也可能很有用。 For example, if you have a folder under your user account, say "C:\Users\Username\Haskell\" in which you have your hello.hs file, you open command prompt by typing cmd, when it opens, you'll see "C:\Users\Username>".
例如,如果您的用户帐户下有一个文件夹,例如“C:\Users\Username\Haskell\”,其中有您的 hello.hs 文件,您可以通过键入 cmd 打开命令提示符,当它打开时,您将请参阅“C:\用户\用户名>”。 To compile you file type the following:
要编译您的文件,请键入以下内容:
ghc Haskell\hello.hs
So the entire line should look like:所以整行应该是这样的:
C:\Users\Username>ghc Haskell\hello.hs
Provided you have no any mistypes, you should be able to see the result in the same folder as you have your hello.hs file.如果您没有任何错误输入,您应该能够在与您的 hello.hs 文件相同的文件夹中看到结果。
You should simply install the Haskell Platform , including GHC and the IDE Leksah.您只需安装Haskell 平台,包括 GHC 和 IDE Leksah。 Using this environment compilation becomes very easy and convenient.
使用这个环境编译变得非常简单方便。
On Windows (without using Cygwin) there are two steps to creating the.exe file from the.hs file:在 Windows(不使用 Cygwin)上,从 .hs 文件创建 .exe 文件有两个步骤:
(1) You need to navigate in the command line terminal to the folder containing your.hs file. (1) 您需要在命令行终端中导航到包含 your.hs 文件的文件夹。 To do so, you can either do:
为此,您可以执行以下任一操作:
(2) You need to compile the.hs file. (2) 需要编译.hs文件。 To do so, you can type after the prompt either:
为此,您可以在提示后键入:
ghc hello.hs
or ghc hello.hs
或ghc --make hello
Either option will produce a hello.exe executable file in the same folder as your hello.hs file.任一选项都会在与 hello.hs 文件相同的文件夹中生成一个 hello.exe 可执行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.