Reputation: 609
I'm testing simple Go program on Windows 8 with SublimeText3 (GoSublime plugin)
go run -v example.go
and before run it's being compiled inside ..AppData\Local\Temp.. directory. My antivirus program thinks that it's a virus and blocks it:
fork/exec C:\Users\D24F7~1.KAP\AppData\Local\Temp\go-build333212398\command-line-arguments_obj\exe\example.exe: Access is denied.
I can't disable it and my solution is to change the folder where it's being compiled. How can I do that?
Upvotes: 19
Views: 11968
Reputation: 293
I change ouput directory
go build -i -o D:\Users\MyProj\out\
-o flag
and put to antivirus ignoring D:\Users\MyProj\out\ directory
Upvotes: 0
Reputation: 2329
The GOTMPDIR
environment var can be used to control the work directory. This is usually preferable to modifying the system-wide temporary directory. GOTMPDIR
was introduced in go 1.10.
Before
> go run -work .\example.go
WORK=C:\Users\MyUserName\AppData\Local\Temp\go-build1002945170
...
Modify permanently in the System Properties > Environment Variables window or temporarily in the shell
# powershell
$env:GOTMPDIR = "C:\Users\MyUserName\MyGoBuilds"
After
> go run -work .\example.go
WORK=C:\Users\MyUserName\MyGoBuilds\go-build1381354702
...
Then you can make the needed antivirus or other security exceptions on the GOTMPDIR
directory.
Upvotes: 14
Reputation: 705
The WORK
directory (seen if building or running with the -x
flag) is taken from the TMP
environment variable. Updating that variable through the system properties will change the working directory.
Upvotes: 3
Reputation: 1008
You can build a binary directly using go build
(out binary is at current dir) or go build -o /your/custom/path
. Then just run the output binary.
Upvotes: -1