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

doc: clarify usage of CGO_ENABLED #9530

Closed
mdempsky opened this issue Jan 7, 2015 · 5 comments
Closed

doc: clarify usage of CGO_ENABLED #9530

mdempsky opened this issue Jan 7, 2015 · 5 comments

Comments

@mdempsky
Copy link
Contributor

mdempsky commented Jan 7, 2015

I was trying to repro issue #9510. I'm on a linux/amd64 system, and I used "GOARCH=386 ./make.bash --no-clean" to setup a cross-compiler toolchain. However, subsequently running "GOARCH=386 go build issue" per iant@'s instructions yielded an unhelpful "no buildable Go source files in .../issue/a" error.

Poking into the package go/build source code, I discovered mention of "CGO_ENABLED" so I tried "GOARCH=386 CGO_ENABLED=1 go build issue". This worked to reproduce the issue.

However, trying to learn more about this setting, I found this in cmd/cgo/doc.go:

To enable cgo during cross compiling builds, set the CGO_ENABLED
environment variable to 1 when building the Go tools with make.bash.

So I inferred I was misusing it and decided to startover with "GOARCH=386 CGO_ENABLED=1 ./make.bash --no-clean" instead, but then running just "GOARCH=386 go build issue" again produced the same "no buildable Go source files" error.

Confusingly, src/make.bash also seems to mention CGO_ENABLED having some significance, but at the moment (even having poked through run.bash and grep'd the source code), I'm still not sure I entirely understand the significance.

@minux
Copy link
Member

minux commented Jan 8, 2015

If you used
GOARCH=386 ./make.bash --no-clean to build Go, then
cgo should be automatically enabled if you use
$GOROOT/bin/linux_386/go, but not if you use
GOARCH=386 $GOROOT/bin/go

Whether cgo is enabled or not is being embedded into the
native Go command. And setting GOARCH to a Go command
for different GOARCH will automatically disable cgo unless
you also set CGO_ENABLED=1.

Yes, this might be confusing.

@davecheney
Copy link
Contributor

Hello,

I was the one that made that change last year. There is some background in
the CL, https://codereview.appspot.com/8134043 (not as much as I had
hoped), and references issue #5141

On Thu, Jan 8, 2015 at 10:39 AM, Matthew Dempsky notifications@github.com
wrote:

I was trying to repro issue #9510
#9510. I'm on a linux/amd64 system,
and I used "GOARCH=386 ./make.bash --no-clean" to setup a cross-compiler
toolchain. However, subsequently running "GOARCH=386 go build issue" per
iant@'s instructions yielded an unhelpful "no buildable Go source files
in .../issue/a" error.

Poking into the package go/build source code, I discovered mention of
"CGO_ENABLED" so I tried "GOARCH=386 CGO_ENABLED=1 go build issue". This
worked to reproduce the issue.

However, trying to learn more about this setting, I found this in
cmd/cgo/doc.go:

To enable cgo during cross compiling builds, set the CGO_ENABLED
environment variable to 1 when building the Go tools with make.bash.

So I inferred I was misusing it and decided to startover with "GOARCH=386
CGO_ENABLED=1 ./make.bash --no-clean" instead, but then running just
"GOARCH=386 go build issue" again produced the same "no buildable Go source
files" error.

Confusingly, src/make.bash also seems to mention CGO_ENABLED having some
significance, but at the moment (even having poked through run.bash and
grep'd the source code), I'm still not sure I entirely understand the
significance.


Reply to this email directly or view it on GitHub
#9530.

@rsc rsc added this to the Go1.5 milestone Apr 10, 2015
@paralin
Copy link
Contributor

paralin commented Jul 9, 2015

I'm having the problem at the moment with this error, even when I define CGO_ENABLED when cross compiling a go program, as well as when I try to compile the Go compiler with CGO_ENABLED.

What's the correct way to do this?

I'm going amd64 -> arm by the way.

@ianlancetaylor
Copy link
Contributor

@paralin Please ask questions on the mailing list golang-nuts@googlegroups.com, rather than dropping a question into an issue. Thanks.

I'm not sure what error you mean here. In your e-mail to golang-nuts, please say exactly what you did, exactly what happened, and what you expected to happen instead.

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/12603 mentions this issue.

@golang golang locked and limited conversation to collaborators Aug 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants