Go version
go version go1.22.4 linux/amd64
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/me/.cache/go-build'
GOENV='/home/me/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/mccd/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/mccd/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/mccd/builds/sustainably-go/go.mod'
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2635966091=/tmp/go-build -gno-record-gcc-switches'
What did you do?
To cross compile a static binary for OpenBSD when running on Alpine linux, I ran the following
CGO_ENABLED=1 GOOS=openbsd CC=/usr/bin/x86_64-alpine-linux-musl-gcc go build --ldflags '-linkmode external -extldflags -static' .
Cgo was a necessity because of my use of go-sqlite3
What did you see happen?
# net
/usr/lib/go/src/net/cgo_resold.go:20:76: cannot use _Ctype_size_t(len(b)) (value of type _Ctype_ulong) as _Ctype_uint value in argument to (_C2func_getnameinfo)
I got the following error
What did you expect to see?
I expected it to compile without error
Comment From: gabyhelp
Similar Issues
- cmd/go: problems with cgo_resnew when cross-compiling on freebsd for linux #66839
- cmd/go: build constraints sometimes ineffective for net/cgo_resnew.go on FreeBSD #33101
- CGo-enabled cross compilation (amd64 -> arm64) failed #39615
- cmd/go: document system setup for cross compiling between linux architectures #47175
- internal compiler error: bad type for ... argument: [2]string #45913
- cmd/cgo: Wrong types in compiler errors with clang 14 #53013
- cmd/cgo: cannot convert from signed char *_Ctype_schar to char *_Ctype_char #26655
- cmd/cgo: When building cgo, I get an error 'could not determine kind of name for var' #23819
- cross compiling issue #66642
- x/pkgsite: cannot build golang1.9 on centos6 with lib2.10 #59328
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: ianlancetaylor
When you are cross-compiling from Linux to OpenBSD, you must set CC
to a C cross-compiler from Linux to OpenBSD. That C cross-compiler must read the OpenBSD header files, not the Linux ones.