Skip to content

cross compiling issue #66642

Closed as not planned
Closed as not planned
@Goplush

Description

@Goplush

Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/.gvm/pkgsets/go1.22.1/global/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/.gvm/pkgsets/go1.22.1/global'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/root/.gvm/gos/go1.22.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/root/.gvm/gos/go1.22.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='/opt/x-tools/arm-linux-musleabi-cross/bin/arm-linux-musleabi-cc'
CXX='/opt/x-tools/arm-linux-musleabi-cross/bin/arm-linux-musleabi-cpp'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4118037362=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I tried to build a project, but cgo code kept failing

code demo:

package main

import(
	"fmt"
	"gopkg.in/olebedev/go-duktape.v3"
)

func main()  {
	
	ctx := duktape.New()
	ctx.PushGlobalGoFunction("log", func(c *duktape.Context) int {
	  fmt.Println(c.SafeToString(-1))
	  return 0
	})
	ctx.PevalString(`log('Go lang Go!')`)
	
}

What did you see happen?

In command line:
go build -o main2 main.go
# runtime/cgo
In file included from _cgo_export.c:4:
cgo-gcc-export-header-prolog:31:14: error: size of array ‘_check_for_64_bit_pointer_matching_GoInt’ is negative

What did you expect to see?

compile fine when GOARCH is set to host arch, but fail when cross compile to arm64

what can I do to fix this inconsistent behavior?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions