我可以运行第一个代码,但不能在Windows中构建它

时间:2019-11-28 09:22:46

标签: go build

我正在尝试在Windows 10上设置Go,

我从网站上下载并安装了MSI文件go1.13.4.windows-amd64.msi。

这是我的Go版本:go版本go1.13.4 windows / amd64

这是我去的环境:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=E:\MyGoProjects\bin
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\MyGoProjects
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\Tools\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Tools\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build686105498=/tmp/go-build -gno-record-gcc-switches

这是我的第一个main.go代码:

package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello World!")
}

我可以像这样运行我的第一个hello.go:

e:\MyGoProjects\src\kira>go run main.go
Hello World!

但是,我无法构建或安装它。

e:\MyGoProjects\src\kira>go build main.go
open C:\Users\ADMINI~1\AppData\Local\Temp\go-build350412618\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.

e:\MyGoProjects>go build src/kira/main.go
open C:\Users\ADMINI~1\AppData\Local\Temp\go-build072798966\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.

e:\MyGoProjects\src>go build kira/main.go
open C:\Users\ADMINI~1\AppData\Local\Temp\go-build762546350\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.

我添加了“ -x”以显示详细信息。

当我运行它时它会起作用:

e:\MyGoProjects\src\kira>go run -x main.go
WORK=C:\Users\ADMINI~1\AppData\Local\Temp\go-build298627166
mkdir -p $WORK\b001\
cat >$WORK\b001\importcfg << 'EOF' # internal
# import config
packagefile fmt=D:\Tools\Go\pkg\windows_amd64\fmt.a
packagefile runtime=D:\Tools\Go\pkg\windows_amd64\runtime.a
EOF
cd e:\MyGoProjects\src\kira
"D:\\Tools\\Go\\pkg\\tool\\windows_amd64\\compile.exe" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build298627166\\b001\\_pkg_.a" -trimpath "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build298627166\\b001=>" -p main -complete -buildid zDvfD24YcsDo7qFI7zul/zDvfD24YcsDo7qFI7zul -dwarf=false -goversion go1.13.4 -D _/e_/MyGoProjects/src/kira -importcfg "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build298627166\\b001\\importcfg" -pack -c=4 "e:\\MyGoProjects\\src\\kira\\main.go"
"D:\\Tools\\Go\\pkg\\tool\\windows_amd64\\buildid.exe" -w "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build298627166\\b001\\_pkg_.a" # internal
cp "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build298627166\\b001\\_pkg_.a" "C:\\Users\\Administrator\\AppData\\Local\\go-build\\55\\55570367d333aa17087e6d6db8a4798606162d2a32b1587f9ba8751895687fe4-d" # internal
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile command-line-arguments=$WORK\b001\_pkg_.a
packagefile fmt=D:\Tools\Go\pkg\windows_amd64\fmt.a
packagefile runtime=D:\Tools\Go\pkg\windows_amd64\runtime.a
packagefile errors=D:\Tools\Go\pkg\windows_amd64\errors.a
packagefile internal/fmtsort=D:\Tools\Go\pkg\windows_amd64\internal\fmtsort.a
packagefile io=D:\Tools\Go\pkg\windows_amd64\io.a
packagefile math=D:\Tools\Go\pkg\windows_amd64\math.a
packagefile os=D:\Tools\Go\pkg\windows_amd64\os.a
packagefile reflect=D:\Tools\Go\pkg\windows_amd64\reflect.a
packagefile strconv=D:\Tools\Go\pkg\windows_amd64\strconv.a
packagefile sync=D:\Tools\Go\pkg\windows_amd64\sync.a
packagefile unicode/utf8=D:\Tools\Go\pkg\windows_amd64\unicode\utf8.a
packagefile internal/bytealg=D:\Tools\Go\pkg\windows_amd64\internal\bytealg.a
packagefile internal/cpu=D:\Tools\Go\pkg\windows_amd64\internal\cpu.a
packagefile runtime/internal/atomic=D:\Tools\Go\pkg\windows_amd64\runtime\internal\atomic.a
packagefile runtime/internal/math=D:\Tools\Go\pkg\windows_amd64\runtime\internal\math.a
packagefile runtime/internal/sys=D:\Tools\Go\pkg\windows_amd64\runtime\internal\sys.a
packagefile internal/reflectlite=D:\Tools\Go\pkg\windows_amd64\internal\reflectlite.a
packagefile sort=D:\Tools\Go\pkg\windows_amd64\sort.a
packagefile sync/atomic=D:\Tools\Go\pkg\windows_amd64\sync\atomic.a
packagefile math/bits=D:\Tools\Go\pkg\windows_amd64\math\bits.a
packagefile internal/oserror=D:\Tools\Go\pkg\windows_amd64\internal\oserror.a
packagefile internal/poll=D:\Tools\Go\pkg\windows_amd64\internal\poll.a
packagefile internal/syscall/windows=D:\Tools\Go\pkg\windows_amd64\internal\syscall\windows.a
packagefile internal/testlog=D:\Tools\Go\pkg\windows_amd64\internal\testlog.a
packagefile syscall=D:\Tools\Go\pkg\windows_amd64\syscall.a
packagefile time=D:\Tools\Go\pkg\windows_amd64\time.a
packagefile unicode/utf16=D:\Tools\Go\pkg\windows_amd64\unicode\utf16.a
packagefile unicode=D:\Tools\Go\pkg\windows_amd64\unicode.a
packagefile internal/race=D:\Tools\Go\pkg\windows_amd64\internal\race.a
packagefile internal/syscall/windows/sysdll=D:\Tools\Go\pkg\windows_amd64\internal\syscall\windows\sysdll.a
packagefile internal/syscall/windows/registry=D:\Tools\Go\pkg\windows_amd64\internal\syscall\windows\registry.a
EOF
mkdir -p $WORK\b001\exe\
cd .
"D:\\Tools\\Go\\pkg\\tool\\windows_amd64\\link.exe" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build298627166\\b001\\exe\\main.exe" -importcfg "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build298627166\\b001\\importcfg.link" -s -w -buildmode=exe -buildid=i7YNMCdprYM4mKyfUqJA/zDvfD24YcsDo7qFI7zul/7HovXSgzGxAAySCtO7aw/i7YNMCdprYM4mKyfUqJA -extld=gcc "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build298627166\\b001\\_pkg_.a"
$WORK\b001\exe\main.exe
Hello World!

当我尝试构建它时,出现此错误:

e:\MyGoProjects\src\kira>go build -x
WORK=C:\Users\ADMINI~1\AppData\Local\Temp\go-build071668470
mkdir -p $WORK\b001\
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile kira=C:\Users\Administrator\AppData\Local\go-build\6a\6aa0e6980ceeaa81ee21821ee9fb34509e98334ce6f2028642325b75ebbc720a-d
packagefile fmt=D:\Tools\Go\pkg\windows_amd64\fmt.a
packagefile runtime=D:\Tools\Go\pkg\windows_amd64\runtime.a
packagefile errors=D:\Tools\Go\pkg\windows_amd64\errors.a
packagefile internal/fmtsort=D:\Tools\Go\pkg\windows_amd64\internal\fmtsort.a
packagefile io=D:\Tools\Go\pkg\windows_amd64\io.a
packagefile math=D:\Tools\Go\pkg\windows_amd64\math.a
packagefile os=D:\Tools\Go\pkg\windows_amd64\os.a
packagefile reflect=D:\Tools\Go\pkg\windows_amd64\reflect.a
packagefile strconv=D:\Tools\Go\pkg\windows_amd64\strconv.a
packagefile sync=D:\Tools\Go\pkg\windows_amd64\sync.a
packagefile unicode/utf8=D:\Tools\Go\pkg\windows_amd64\unicode\utf8.a
packagefile internal/bytealg=D:\Tools\Go\pkg\windows_amd64\internal\bytealg.a
packagefile internal/cpu=D:\Tools\Go\pkg\windows_amd64\internal\cpu.a
packagefile runtime/internal/atomic=D:\Tools\Go\pkg\windows_amd64\runtime\internal\atomic.a
packagefile runtime/internal/math=D:\Tools\Go\pkg\windows_amd64\runtime\internal\math.a
packagefile runtime/internal/sys=D:\Tools\Go\pkg\windows_amd64\runtime\internal\sys.a
packagefile internal/reflectlite=D:\Tools\Go\pkg\windows_amd64\internal\reflectlite.a
packagefile sort=D:\Tools\Go\pkg\windows_amd64\sort.a
packagefile sync/atomic=D:\Tools\Go\pkg\windows_amd64\sync\atomic.a
packagefile math/bits=D:\Tools\Go\pkg\windows_amd64\math\bits.a
packagefile internal/oserror=D:\Tools\Go\pkg\windows_amd64\internal\oserror.a
packagefile internal/poll=D:\Tools\Go\pkg\windows_amd64\internal\poll.a
packagefile internal/syscall/windows=D:\Tools\Go\pkg\windows_amd64\internal\syscall\windows.a
packagefile internal/testlog=D:\Tools\Go\pkg\windows_amd64\internal\testlog.a
packagefile syscall=D:\Tools\Go\pkg\windows_amd64\syscall.a
packagefile time=D:\Tools\Go\pkg\windows_amd64\time.a
packagefile unicode/utf16=D:\Tools\Go\pkg\windows_amd64\unicode\utf16.a
packagefile unicode=D:\Tools\Go\pkg\windows_amd64\unicode.a
packagefile internal/race=D:\Tools\Go\pkg\windows_amd64\internal\race.a
packagefile internal/syscall/windows/sysdll=D:\Tools\Go\pkg\windows_amd64\internal\syscall\windows\sysdll.a
packagefile internal/syscall/windows/registry=D:\Tools\Go\pkg\windows_amd64\internal\syscall\windows\registry.a
EOF
mkdir -p $WORK\b001\exe\
cd .
"D:\\Tools\\Go\\pkg\\tool\\windows_amd64\\link.exe" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build071668470\\b001\\exe\\a.out.exe" -importcfg "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build071668470\\b001\\importcfg.link" -buildmode=exe -buildid=UWXJvMF3R81CJ8MzEe08/KtLDKptAH3ZGnT3c2lqY/X_przzpSPGA6aMioX9b9/UWXJvMF3R81CJ8MzEe08 -extld=gcc "C:\\Users\\Administrator\\AppData\\Local\\go-build\\6a\\6aa0e6980ceeaa81ee21821ee9fb34509e98334ce6f2028642325b75ebbc720a-d"
"D:\\Tools\\Go\\pkg\\tool\\windows_amd64\\buildid.exe" -w "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build071668470\\b001\\exe\\a.out.exe" # internal
open C:\Users\ADMINI~1\AppData\Local\Temp\go-build071668470\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.

0 个答案:

没有答案