运行从Haskell项目构建的exe文件时,停止打开命令提示符 [英] Stop command prompt from opening when running exe file built from haskell project
问题描述
我创建了一个小应用程序,该应用程序将光泽度库用于GUI.当键入"cabal run [cabal file]"时,该项目已构建并运行,并且仅提示GUI.相反,当我单击从生成生成的.exe文件时,GUI会打开,但命令提示符也会打开.我想停止命令提示符的打开,而只打开光泽窗口.
I have created a small application that uses the gloss library for a GUI. When typing "cabal run [cabal file]" the project is built and run, and only prompts the GUI. When I instead go and click on the .exe file that was generated from the build, the GUI opens but so does the command prompt. I want to stop the command prompt from opening and only have the window from gloss open.
推荐答案
默认情况下,Windows GHC会构建控制台程序,如果尚未打开命令提示符终端,则会打开该命令提示符终端.如果要构建仅GUI的程序,可以通过将 -optl -mwindow
标志赋予GHC来将 -mwindow
传递给链接器.如果您使用Cabal,则可以将此标志添加到可执行文件节中的 ghc-options
字段中.
By default on Windows GHC builds console programs, which open a Command Prompt terminal if one isn’t open already. If you want to build a GUI-only program, you can pass -mwindow
to the linker by giving the -optl -mwindow
flag to GHC. If you’re using Cabal, you would add this flag to the ghc-options
field in the executable stanza.
请注意,如果使用此标志,则程序将没有任何 stdin
, stdout
或 stderr
文件句柄,因此应采取类似操作 putStrLn
, print
和 getLine
将不起作用,因为它们等效于 hPutStrLn stdout
,hPrint stdout
和 hGetLine stdin
.如果您想进行任何日志记录或打印,则需要自己打开一个句柄(例如,文件,终端或带有读取另一端的另一个程序的套接字);但是,如果您需要临时跟踪进行调试,则 Debug.Trace
仍然可以使用.
Beware that if you use this flag, your program will not have any stdin
, stdout
, or stderr
file handles, so actions like putStrLn
, print
, and getLine
will not work, since they’re equivalent to hPutStrLn stdout
, hPrint stdout
, and hGetLine stdin
. If you want to do any logging or printing, you’ll need to open a handle yourself (e.g. a file, terminal, or socket with another program reading the other end); however, Debug.Trace
will still work if you need temporary tracing for debugging.
您可以在 查看全文