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: be lazy about cgo complaints, to enable cross compiles #2822

Closed
rsc opened this issue Jan 31, 2012 · 5 comments
Closed

cmd/go: be lazy about cgo complaints, to enable cross compiles #2822

rsc opened this issue Jan 31, 2012 · 5 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jan 31, 2012

---------- Forwarded message ----------
From: Stetson <stetsongafford@gmail.com>
Date: Thu, Jan 26, 2012 at 11:12
Subject: [go-nuts] Cross compiling OSX to Linux 386 with Go tool ("cannot use cgo
when compiling for a different operating system")
To: golang-nuts <golang-nuts@googlegroups.com>


Hi all,

I've been developing with Go on OSX targeting Linux 386 for about 8
months, but now I'm trying to do so with the latest Weekly (01-20).

I installed and compiled the weekly under OSX, and then did the same
in a Linux VM and copied the /pkg/linux_386/ folder over to the OSX
install, which is how I did it before.

I've mostly figured out how to use the go tool for building and
installing my own packages, and I like it a lot now that I'm used to
it, but it doesn't seem to like cross compiling when using packages
that rely on cgo.

When I try to compile my package (which imports net/http, which I
think relies on cgo) with GOOS=linux using 8g, it seems to work just
fine. When I try to 'go install' the package, I get the error "cannot
use cgo when compiling for a different operating system".

Do I just need to do all of my compiling and copying manually or is
there some way to use the go tool with this setup?

Thanks
@rsc
Copy link
Contributor Author

rsc commented Jan 31, 2012

Comment 1:

Labels changed: added priority-go1, removed priority-triage.

@bsiegert
Copy link
Contributor

bsiegert commented Feb 1, 2012

Comment 2:

I think you can use
env GOOS=linux GOARCH=386 DISABLE_CGO=1 go install all

@rsc
Copy link
Contributor Author

rsc commented Mar 7, 2012

Comment 3:

This should be fixed now.  If you are working outside $GOROOT
(in a $GOPATH), then the go command does not try to recompile
packages inside $GOROOT, which means it will not try to recompile
net, which means it will not invoke cgo, which means it will not
provoke that message.

Status changed to Fixed.

@gopherbot
Copy link

Comment 4 by alltom:

On release (12872:920e9d1ffd1f), bsiegert's command works for me so long as I change
DISABLE_CGO=1 to CGO_ENABLED=0. Without that flag, I get the same "cannot use cgo
when..." error as Stetson when "go build" tries to build runtime/cgo.

@rsc
Copy link
Contributor Author

rsc commented Apr 10, 2012

Comment 5:

If the go command is rebuilding runtime/cgo, then either you haven't built it at all or
you are not working outside $GOROOT.

@rsc rsc added fixed labels Apr 10, 2012
@rsc rsc self-assigned this Apr 10, 2012
@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
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

3 participants