'Go programs hanging on Windows 10
I've been having issues with all Go programs hanging on Windows, even a simple Hello world program. I've reinstalled Golang multiple times with nothing changing. I can't use Ctrl+X or Ctrl+D to close the program either. It'll still spawn the process which will show up on Process Monitor. But I can't kill it from there or from the command line.
There was a similar issue to this posted on reddit https://www.reddit.com/r/golang/comments/2lvnqk/not_even_hello_world_works/. But that still has no resolution.
The is the program I'm trying to get to run right now:
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
Running it with go run -x gives this output:
WORK=C:\Users\User\AppData\Local\Temp\go-build882050150
mkdir -p $WORK\command-line-arguments\_obj\
mkdir -p $WORK\command-line-arguments\_obj\exe\
cd E:\go\src\github.com\test\hello
"C:\\Go\\pkg\\tool\\windows_amd64\\compile.exe" -o "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150\\command-line-arguments.a" -trimpath "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150" -p main -complete -buildid 0180ed6e175ea3e4bc497fc21fe0319a733a9c8e -D _/E_/go/src/github.com/test/hello -I "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150" -pack "E:\\go\\src\\github.com\\test\\hello\\main.go"
cd .
"C:\\Go\\pkg\\tool\\windows_amd64\\link.exe" -o "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150\\command-line-arguments\\_obj\\exe\\main.exe" -L "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150" -w -extld=gcc -buildmode=exe -buildid=0180ed6e175ea3e4bc497fc21fe0319a733a9c8e "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150\\command-line-arguments.a"
$WORK\command-line-arguments\_obj\exe\main.exe
After that it just sits there and dose nothing. Doesn't matter what program I run it will always hang forever.
No idea where to go from here. I don't really develop on Windows but I was trying to work with cross-compilation on Ubuntu and having run into this issue with the cross-compiled binary I thought I'd try compiling directly on Windows. But it appears my Windows just doesn't like Golang compiled binaries.
Go version is 1.5.1 windows/amd64.
Here's the output of go env:
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
Solution 1:[1]
The problem is that if GOTMPDIR is not set, golang will sometimes build in that generic \Temp directory that is dangerous to allow as a generic exception to Kaspersky. And for me, Kaspersky doesn't allow wildcards in the directory exceptions like Avast
Assuming you've already added your GOPATH as an exception in your antivirus (for example, "C:\Users<user>\go"...what worked for me was to
- add a new directory (I named mine "tmp" but you could probably name it a number of things) within that path, i.e., "C:\Users<user>\go\tmp"
- Set the golang environment variable GOTMPDIR to it...
go env -w GOTMPDIR="C:\Users<user>\go\tmp"
And the issue goes away. But note that I already added "C:\Users<user>\go" as an exception to my antivirus.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gronkey Kong Jr |
