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: confusing "build constraints exclude all Go files" error when trying to cross-compile a package that uses CGO #29074

Open
imwaddy opened this Issue Dec 3, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@imwaddy

imwaddy commented Dec 3, 2018

go version
go version go1.10.4 linux/amd64

go env
GOARCH="amd64"
GOBIN="/home/mayurw/go/bin"
GOCACHE="/home/mayurw/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mayurw/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build555451646=/tmp/go-build -gno-record-gcc-switches"

I executed the command
env GOOS=linux GOARCH=arm64 go build
it produced output as bolow
go build github.com/DataDog/zstd: build constraints exclude all Go files in ~/go/src/github.com/DataDog/zstd

I'm really not getting what error it is. Please provide solution to go cross compilation from linux to ARM architecture binaries..

@mvdan

This comment has been minimized.

Member

mvdan commented Dec 3, 2018

You already opened this issue as DataDog/zstd#46. Please keep the discussion there, as this isn't a bug in Go.

You can't cross-compile a package that uses CGO - that's where the error comes from. You'll see the same error if you try CGO_ENABLED=0 go build.

I honestly don't know if cross compiling with CGO is a good idea, but you could try existing workarounds like https://github.com/karalabe/xgo.

@mvdan mvdan closed this Dec 3, 2018

@mvdan

This comment has been minimized.

Member

mvdan commented Dec 3, 2018

Actually, I think the error message here could be clearer. On a first scan of the package, there are no Go files with build constraints, so it can seem like the error is wrong. Only if one is aware of CGO does the error make sense.

Perhaps the error should somehow point at CGO instead of saying "build constraints exclude all Go files".

/cc @bcmills @ianlancetaylor

@mvdan mvdan reopened this Dec 3, 2018

@mvdan mvdan changed the title from cannot cross-compile arm binary on x86 platform to cmd/go: confusing "build constraints exclude all Go files" error when trying to cross-compile a package that uses CGO Dec 3, 2018

@bcmills bcmills added this to the Go1.13 milestone Dec 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment