Stop command prompt from opening when running exe file built from haskell project

旧街凉风 提交于 2020-12-12 09:38:05

问题


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.


回答1:


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.

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.

You can find more helpful reference information in the GHC User’s Guide §16. Running GHC on Win32 Systems.



来源:https://stackoverflow.com/questions/65079183/stop-command-prompt-from-opening-when-running-exe-file-built-from-haskell-projec

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