如何从Golang创建可执行文件,该可执行文件在运行时不会打开控制台窗口?

问题描述:

我创建了一个想要在后台隐形运行的应用程序(无控制台)。我该怎么做?

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

(这是Windows系统,在Windows 7 Pro 64位上测试)

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

在线找到的文档说我可以使用类似的东西进行编译,

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

go build -ldflags -Hwindowsgui filename.go

但这会产生错误: unknown flag -Hwindowsgui

使用较新的(1.1?)版本的编译器,这应该可以工作:

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.