How do I create an executable from Golang that doesn't open a console window when run?

后端 未结 3 1549
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 07:43

I created an application that I want to run invisibly in the background (no console). How do I do this?

(This is for Windows, tested on Windows 7 Pro 64 bit)

3条回答
  •  清歌不尽
    2020-12-02 08:20

    The documentation found online says I can compile with something along the lines of,

    go build -ldflags -Hwindowsgui filename.go

    But this gives an error: unknown flag -Hwindowsgui

    With more recent (1.1?) versions of the compiler, this should work:

    go build -ldflags -H=windowsgui filename.go

    When I continued searching around I found a note that the official documentation should be updated soon, but in the meantime there are a lot of older-style example answers out there that error.

提交回复
热议问题