Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go build error. open C:\Users\...\a.out.exe: The process cannot access the file because it is being used by another process. #29093

Closed
jcuan opened this issue Dec 4, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@jcuan
Copy link

commented Dec 4, 2018

What version of Go are you using (go version)?

$ go version
go version go1.11.2 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

windows 10 1803
10.0.17134
go env Output
$ go env
go version go1.11.2 windows/amd64
PS D:\code\go> go env
set GOARCH=amd64
set GOBIN=D:\tools\gobin
set GOCACHE=C:\Users\SHEXIA~1\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\code\go
set GOPROXY=
set GORACE=
set GOROOT=D:\tools\go11
set GOTMPDIR=
set GOTOOLDIR=D:\tools\go11\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\SHEXIA~1\AppData\Local\Temp\go-build536614342=/tmp/go-build -gno-record-gcc-switches

What did you do?

#build successfully
PS D:\code\go\src> go build -o out.exe .\main.go
#update code, build failed
PS D:\code\go\src> go build -o out.exe .\main.go
open C:\Users\SHEXIA~1\AppData\Local\Temp\go-build047301674\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.
PS D:\code\go\src> go build -o out.exe .\main.go
open C:\Users\SHEXIA~1\AppData\Local\Temp\go-build838661906\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.
#wait a few minutes, build successfully again
PS D:\code\go\src> go build -o out.exe .\main.go

@ianlancetaylor ianlancetaylor changed the title go build error. open C:\Users\...\a.out.exe: The process cannot access the file because it is being used by another process. cmd/go: go build error. open C:\Users\...\a.out.exe: The process cannot access the file because it is being used by another process. Dec 5, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2018

Is this repeatable? What are the contents of main.go?

@jcuan

This comment has been minimized.

Copy link
Author

commented Dec 5, 2018

@ianlancetaylor

This problem happens every time after I use go build .The Contents of main.go is simple and all my projects have this problem.

package main

import "fmt"

func main() {
    fmt.Println("jcuan")
}
@agnivade

This comment has been minimized.

Copy link
Member

commented Dec 5, 2018

This problem happens every time after I use go build .

That does not seem to match this statement of yours.

#wait a few minutes, build successfully again

So it looks like some process is possibly using a.out.exe for some time. I don't know what is the lsof equivalent in Windows, but are you sure that no process is actually using a.out.exe ?

@jcuan

This comment has been minimized.

Copy link
Author

commented Dec 5, 2018

@agnivade @ianlancetaylor

This problem happens every time after I use go build .

I mean I must wait a few minutes in order to build successfully again almost every time after using go build.

Now, I find that maybe it's caused by vscode/go extension in vscode. Yesterday, I turn off vscode and use notepad to edit code, which doesn't fix this problem. But today, I rebooted my computer and didn't open vscode before using go build and I didn't encounter this problem again after many tries. Then I opened vscode and this problem appeared again but the probability was very low.

Thank you both~ 😁

@jcuan jcuan closed this Dec 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.