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)
From the command line in the hello directory, run the go build command to compile the code into an executable. From the command line in the hello directory, run the new hello executable to confirm that the code works.
1 Answer. Show activity on this post. As long as any dependencies your program has are installed on the machine running the program, or your program is statically compiled, the user will be able to run your program without installing anything.
In the \Users\SomeUser\AppData\Local\Temp\ if you're on windows.
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.
Using Go Version 1.4.2
go build -ldflags "-H windowsgui"
From the Go docs:
go build [-o output] [-i] [build flags] [packages]
-ldflags 'flag list'
arguments to pass on each 5l, 6l, or 8l linker invocation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With