-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/cgo: support cross compilation with cgo enabled #4714
Labels
Milestone
Comments
This would also mean I could cross-compile linux-arm-cgo Android child helper binaries from darwin-amd64 and be able to do proper Android DNS lookups. Currently, without cgo, I can't do native DNS so I'm resorting to hacks like using os/exec and parsing the first line output of "ping -c 1 $HOSTNAME" for my http.Transport's net.Dial function. |
Hi brad, for now you can use a gcc wrapper to enable cgo cross compilation with Android NDK, https://golang.org/cl/6454055/ |
Issue #5848 has been merged into this issue. |
What's needed to resolve this? FWIW I'm successfully cross compiling from darwin amd64 to linux 386 via 'CC=$(CC) CGO_ENABLED=1 GOOS=linux GOARCH=386 go build -x -ldflags="-extld=$(CC)"' (where $(CC) is "i686-nptl-linux-gnu-gcc" in this instance) and disabling the "cannot use cgo" error in src/cmd/go/build.go: diff -r 3d177aef8dd3 src/cmd/go/build.go --- a/src/cmd/go/build.go Mon Jul 22 23:02:27 2013 +0400 +++ b/src/cmd/go/build.go Thu Aug 01 13:34:13 2013 +0200 @@ -1854,9 +1854,9 @@ ) func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string, gxxfiles []string) (outGo, outObj []string, err error) { - if goos != toolGOOS { - return nil, nil, errors.New("cannot use cgo when compiling for a different operating system") - } + // if goos != toolGOOS { + // return nil, nil, errors.New("cannot use cgo when compiling for a different operating system") + // } cgoCPPFLAGS := stringList(envList("CGO_CPPFLAGS"), p.CgoCPPFLAGS) cgoCFLAGS := stringList(envList("CGO_CFLAGS"), p.CgoCFLAGS) |
Started: https://golang.org/cl/57100043 |
This issue was updated by revision 2dc759d. LGTM=minux.ma, iant R=golang-codereviews, minux.ma, iant, rsc, dominik.honnef CC=golang-codereviews https://golang.org/cl/57100043 Committer: Ian Lance Taylor |
As of rev. 6d3bdbd27761, the missing parts of this issue are, as I see them: 1. make.bat/make.rc support for CC_FOR_TARGET. 2. Support for remote testing. Minux tells me that the upcoming NaCL port includes a mechanism for go test to use a helper binary to execute cross compiled tests. I think Dave is working on getting that port up to date and submitted. 3. Documentation for setting up various cross compilers. |
Comment 16 by joe@prevoty.com: As of right now this patch isn't working. I've attempted to setup a cross compile toolchain on OS X for linux, both on am64 with the following commands from the go tip repo: GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC_FOR_TARGET=/opt/local/bin/x86_64-elf-gcc CXX_FOR_TARGET=/opt/local/bin/x86_64-elf-g++ ./make.bash After building I attempted to build source of a project which imports a library that uses CGo using the following command: CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build And get the following result: go build runtime/cgo: cannot use cgo when compiling for a different operating system |
Thank you. It seems I missed a check in the rework of the previous CL. Created https://golang.org/cl/57210046. |
This issue was updated by revision 9b0736f. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/57210046 Committer: Ian Lance Taylor |
Did you have something like https://golang.org/cl/100390043 in mind? |
CL https://golang.org/cl/100390043 mentions this issue. |
This issue was updated by revision 88d07b2. LGTM=iant, minux.ma, rsc R=rsc, iant, r, minux.ma CC=golang-codereviews https://golang.org/cl/100390043 Committer: Russ Cox |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: