windowsgo

Can not run Golang application in 32 bits machine


I build Golang to 32 bits version in 64 bits machine. However, it has a problem, when I build like that, it will take the "kernel32.dll" inside SysWOW64 folder, but when I run in 32 bits machine (Windows 7). It doesn't have the SysWOW64 folder, so its return an error:

fatal error: kernel32.dll not found

Here is my go build command:

go build -ldflags "-s -w"

Here is my go env:

set GO111MODULE=
set GOARCH=386
set GOBIN=
set GOCACHE=C:\Users\name\AppData\Local\go-build
set GOENV=C:\Users\name\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\name\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\name\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 GO386=sse2
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\Center\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 -MT
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m32 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\name\AppData\Local\Temp\go-build581533674=/tmp/go-build -gno-record-gcc-switches

Can anyone suggest me a solution?


Solution

  • According to @phuclv answer:

    SysWOW64 is the 32-bit System32 on 64-bit Windows. All accesses to %windir%\System32 by a 32-bit application will be redirected to %windir%\SysWOW64.

    So I think in your case, you need to build a 32-bit machine (or virtual machine) then copy and build your code in there. Of course you will have to downgrade some library to match the OS and sometimes it could be challenging.