how to deploy an binary go file developed with 64bit system(mac) to 32bit system(ubuntu)

2,103 views
Skip to first unread message

Zhong Lee

unread,
May 26, 2013, 8:38:57 PM5/26/13
to golan...@googlegroups.com
i did it naively, just scp this file to ubuntu, but it can't run, with error: cannot execute binary file.

so what is the preferred way to deal this situation? put .go files to ubuntu and install there?

Dave Cheney

unread,
May 26, 2013, 8:41:32 PM5/26/13
to Zhong Lee, golang-nuts
Personally i'd just install Go on your target host and compile there,
it's the simplest.

If you want to try cross compiling from darwin/amd64 to linux/386 you
can try, http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go.
Heed the warning that CGO is not supported when cross compiling.
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Zhong Lee

unread,
May 26, 2013, 9:04:50 PM5/26/13
to golan...@googlegroups.com
thanks 4 ur reply. i will choose method 1. also the link provided is very informational and interesting, but a little complicated 4 me.

Matt Silverlock

unread,
May 26, 2013, 9:38:34 PM5/26/13
to golan...@googlegroups.com
Assuming you are using homebrew on your Mac to build/install Go and installed it using `brew install go --cross-compile-common` (or `--cross-compile-all`)

$ GOOS=linux GOARCH=386 go build yourprog.go

That should output a binary that will run on 32-bit Ubuntu, provided you haven't used any cgo libs (as Dave touched on).

Dave Cheney

unread,
May 26, 2013, 9:39:30 PM5/26/13
to Matt Silverlock, golang-nuts
Ahhh, so that is how so many homebrew users end up with go
installations where cgo is disabled.

Matt Silverlock

unread,
May 26, 2013, 9:52:52 PM5/26/13
to golan...@googlegroups.com, Matt Silverlock
Actually, that's my fault - you should have to type:

GOOS=linux GOARCH=386 CGO_ENABLED=0 go build yourprog.go

Homebrew itself still builds Go with cgo enabled for the host system: https://github.com/mxcl/homebrew/blob/master/Library/Formula/go.rb

Dobrosław Żybort

unread,
May 27, 2013, 9:07:32 AM5/27/13
to golan...@googlegroups.com
I know Dave Cheney blog post is very informative (same as rest posts on his blog) but just use goxc for cross compilation:
https://github.com/laher/goxc

Best regards,
Dobrosław Żybort

Dave Cheney

unread,
May 27, 2013, 7:16:10 PM5/27/13
to Dobrosław Żybort, golan...@googlegroups.com
Yes, you should use goxc rather than my shell script. 
Reply all
Reply to author
Forward
0 new messages