"This version of %1 is not compatible.." error

475 views Asked by At

fork/exec C:\Users\user1\AppData\Local\Temp\go-build1624998878\b001\exe\main.exe: This version of %1 is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

This error is thrown whenever I try to run any go files.

I have tested with a simple "hello world" app:

package main

import (
    "fmt"
)

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

and tried various ways of building this (none of which work):

go run main.go
go build main.go
go build -o hello main.go

I already tried:

  • excluding the go files and the work directory from windows defender and antivirus.
  • reinstalling Go and Go extension from the vscode.
  • Unsetting all Go env vars
  • Running the same program with same env vars on another system (successful).

I checked the TEMP directory for the files and it does create new go-build12xxx everytime I run or build. But throws this error. I've already tried both x86 (32-bit) or x64 (64-bit) version of Go though the OS is 64-bit Windows 10. The Go version is go1.21.1.windows-amd64.msi.

What could be the cause and solution of this?

go env:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\user1\AppData\Local\go-build
set GOENV=C:\Users\user1\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\user1\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\user1\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=D:\Inter\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\user1\AppData\Local\Temp\go-build1803464262=/tmp/go-build -gno-record-gcc-switches```


1

There are 1 answers

0
cruel fool On
  1. The solution to this problem as I figured out is to build go file and run this in bash: file ./main.exe It returns something like this:./main.exe: PE32+ executable (console) Aarch64, for MS Windows check whether Aarch64 is compatible with your system.
  2. Run go env and check the value of GOARCH & GOOS.For x86_64 device the value of GOARCH should be amd64 not arm64. To find the list of possible platforms: go tool dist list which returns:
   android/386      freebsd/arm     linux/ppc64    openbsd/amd64
   android/amd64    illumos/amd64   linux/ppc64le  openbsd/arm
   android/arm      js/wasm         linux/s390x    openbsd/arm64
   android/arm64    linux/386       nacl/386       plan9/386
   darwin/386       linux/amd64     nacl/amd64p32  plan9/amd64
   darwin/amd64     linux/arm       nacl/arm       plan9/arm
   darwin/arm       linux/arm64     netbsd/386     solaris/amd64
   darwin/arm64     linux/mips      netbsd/amd64   windows/386
   dragonfly/amd64  linux/mips64    netbsd/arm     windows/amd64
   freebsd/386      linux/mips64le  netbsd/arm64   windows/arm
  
3. Choose which system is yours and change accordingly as per your system. Set the GOARCH values by running following in powershell as administrator:

 ```[System.Environment]::SetEnvironmentVariable('GOARCH','amd64', 'User')``` for User variables
 ```[System.Environment]::SetEnvironmentVariable('GOARCH','amd64', 'Machine')``` for System variables


PS: Though the value of GOARCH is amd64 in the problem, later I realised it was for that session only, not permanent one, hence it is very important to set it permanently. 
You can also refer to this:
https://www.digitalocean.com/community/tutorials/building-go-applications-for-different-operating-systems-and-architectures