Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upcmd/cgo: support cross compilation with cgo enabled #4714
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
bradfitz
Jan 28, 2013
Member
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.
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
minux
Jan 29, 2013
Member
Hi brad, for now you can use a gcc wrapper to enable cgo cross compilation with Android NDK, https://golang.org/cl/6454055/
Hi brad, for now you can use a gcc wrapper to enable cgo cross compilation with Android NDK, https://golang.org/cl/6454055/ |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
|
Issue #5848 has been merged into this issue. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
quarnster
Aug 1, 2013
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)
quarnster
commented
Aug 1, 2013
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)
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
Started: https://golang.org/cl/57100043 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
ianlancetaylor
Feb 6, 2014
Contributor
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
|
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 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
eliasnaur
Feb 7, 2014
Contributor
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.
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
gopherbot
Feb 7, 2014
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
gopherbot
commented
Feb 7, 2014
|
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 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
eliasnaur
Feb 8, 2014
Contributor
Thank you. It seems I missed a check in the rework of the previous CL. Created https://golang.org/cl/57210046.
Thank you. It seems I missed a check in the rework of the previous CL. Created https://golang.org/cl/57210046. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
ianlancetaylor
Feb 14, 2014
Contributor
This issue was updated by revision 9b0736f.
LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/57210046 Committer: Ian Lance Taylor
|
This issue was updated by revision 9b0736f. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/57210046 Committer: Ian Lance Taylor |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
eliasnaur
May 11, 2014
Contributor
Did you have something like https://golang.org/cl/100390043 in mind?
Did you have something like https://golang.org/cl/100390043 in mind? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
gopherbot
commented
May 11, 2014
CL https://golang.org/cl/100390043 mentions this issue. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
rsc
May 20, 2014
Contributor
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 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 comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
minux
added
fixed
labels
May 20, 2014
rsc
added this to the Go1.3 milestone
Apr 14, 2015
rsc
removed
the
release-go1.3maybe
label
Apr 14, 2015
ghost
referenced this issue
Feb 16, 2016
Open
Abstract the Git operation level to allow alternative Git backends #2592
golang
locked and limited conversation to collaborators
Jun 24, 2016
gopherbot
added
the
FrozenDueToAge
label
Jun 24, 2016
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
minux commentedJan 27, 2013