Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.16.2 windows/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env set GO111MODULE= set GOARCH=386 set GOBIN= set GOCACHE=C:\Users\basse\AppData\Local\go-build set GOENV=C:\Users\basse\AppData\Roaming\go\env set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=C:\Users\basse\go\pkg\mod set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=C:\Users\basse\go;C:\Users\basse\source\repos\xhptdc8_babel\go\info\src-cgo; set GOPRIVATE= set GOPROXY=https://proxy.golang.org,direct set GOROOT=C:\Program Files\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.16.2 set GCCGO=gccgo set GO386=sse2 set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=0 set GOMOD=C:\Users\basse\source\repos\xhptdc8_babel\go\info\hello\go.mod 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=-m32 -fmessage-length=0 -fdebug-prefix-map=C:\Users\basse\AppData\Local\Temp\go-build4135007010=/tmp/go-build -gno-record-gcc-switches
What did you do?
I'm using CGO package to import C code, and I want to build an x86 (386) windows version of it. I found out this should be done by setting GOARCH=386.
While it builds properly on my default environment settings (GOARCH=amd64), when I set the environment variable to "386", I get error: build constraints exclude all Go files in
my file.
// hello.go
package main
/*
int CFunc() {
}
*/
import "C"
import (
"fmt"
)
func main() {
fmt.Println("Hello, Go!")
}
go.mod
module hello
go 1.16
I do
go build
Trials:
- Without
import "C"
, I get no error. - With
// +build windows,386
or// +build windows,386,!cgo
before package main I still get the same error
What did you expect to see?
No Error
What did you see instead?
C:\Users\basse\source\repos\xhptdc8_babel\go\info\hello>go build
package hello: build constraints exclude all Go files in C:\Users\basse\source\repos\xhptdc8_babel\go\info\hello