Skip to content
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: problems with cgo_resnew when cross-compiling on freebsd for linux #66839

Closed
ov opened this issue Apr 15, 2024 · 1 comment
Closed

cmd/go: problems with cgo_resnew when cross-compiling on freebsd for linux #66839

ov opened this issue Apr 15, 2024 · 1 comment

Comments

@ov
Copy link

ov commented Apr 15, 2024

Go version

go version go1.22.1 freebsd/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ov/.cache/go-build'
GOENV='/home/ov/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='freebsd'
GOINSECURE=''
GOMODCACHE='/home/ov/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='freebsd'
GOPATH='/home/ov/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go122'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go122/pkg/tool/freebsd_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='cc'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/home/ov/...../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 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2801792256=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I'm trying to cross-compile a project for Linux on a FreeBSD host:

GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC="gcc13" CXX="g++13" go build -ldflags "-extldflags -static" -o app

I tried different CC/CXX options (clang, gcc, amd64-gcc) - they all behave the same.

What did you see happen?

Here's what I get:

GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC="gcc13" CXX="g++13" go build -ldflags "-extldflags -static" -o app
# net
/usr/local/go122/src/net/cgo_resnew.go:20:76: cannot use _Ctype_socklen_t(len(b)) (value of type _Ctype_uint) as _Ctype_ulong value in argument to (_C2func_getnameinfo)

There was a similar discussion about this in #33101 and the solution was to set CGO_ENABLED=0. The problem is that my project has some c++ code that needs to be built, so I can't disable cgo.

If I manually modify the flags in cgo_resnew.go and cgo_resold.go so the latter is used for Linux, the compiling progresses, but it then fails on linking with:

/usr/local/go122/pkg/tool/freebsd_amd64/link: running g++13 failed: exit status 1
/usr/local/bin/ld: cannot find -lresolv: No such file or directory
collect2: error: ld returned 1 exit status

I am not sure if modifying the resnew/old was the right thing, so decided to not dig any deeper and create the report instead.

What did you expect to see?

I expect to be able to do cross-compile builds that use the net module with CGO_ENABLED=1. I can do this on Mac with musl, I can do normal builds on FreeBSD. I expect the cross-builds work on FreeBSD, as well.

Thank you.

@seankhliao
Copy link
Member

Cross compilation C toolchains typically have the target name as part of their executable names. I don't see that here, so it looks like you're trying to use the host toolchain.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants