Go 1.5 cross-compilation

329 views
Skip to first unread message

Henry Adi Sumarto

unread,
Aug 30, 2015, 10:56:15 PM8/30/15
to golang-nuts
Hi,

Now that Go 1.5 is out, I wonder whether it is possible to cross-compile without having to build Go from the source. It would be really great if someone could post a step-by-step instruction for cross-compilation in Go 1.5 here and possibly in the "Effective Go" documentation as well.

Thanks.

Henry 

Dave Cheney

unread,
Aug 30, 2015, 11:30:45 PM8/30/15
to golang-nuts
Yes it is possible. Here is a blog post I wrote last week on the subject.

http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5

Henry Adi Sumarto

unread,
Aug 31, 2015, 1:48:21 AM8/31/15
to golang-nuts
Thanks for the reply, Dave. I am running Windows 10 64-bit and I encountered the following errors. I wonder whether I did something wrong.  


C:\Users\Henry\Documents\Projects\Go\src\has\hello>set goos=linux

C:\Users\Henry\Documents\Projects\Go\src\has\hello>set goarch=arm

C:\Users\Henry\Documents\Projects\Go\src\has\hello>go build -v .
runtime
# runtime
C:\Go\src\runtime\zruntime_defs_linux_arm.go:11: _Gidle redeclared in this block

        previous declaration at C:\Go\src\runtime\runtime2.go:18
C:\Go\src\runtime\zruntime_defs_linux_arm.go:12: _Grunnable redeclared in this b
lock
        previous declaration at C:\Go\src\runtime\runtime2.go:19
C:\Go\src\runtime\zruntime_defs_linux_arm.go:13: _Grunning redeclared in this bl
ock
        previous declaration at C:\Go\src\runtime\runtime2.go:20
C:\Go\src\runtime\zruntime_defs_linux_arm.go:14: _Gsyscall redeclared in this bl
ock
        previous declaration at C:\Go\src\runtime\runtime2.go:21
C:\Go\src\runtime\zruntime_defs_linux_arm.go:15: _Gwaiting redeclared in this bl
ock
        previous declaration at C:\Go\src\runtime\runtime2.go:22
C:\Go\src\runtime\zruntime_defs_linux_arm.go:16: _Gmoribund_unused redeclared in
 this block
        previous declaration at C:\Go\src\runtime\runtime2.go:23
C:\Go\src\runtime\zruntime_defs_linux_arm.go:17: _Gdead redeclared in this block

        previous declaration at C:\Go\src\runtime\runtime2.go:24
C:\Go\src\runtime\zruntime_defs_linux_arm.go:18: _Genqueue redeclared in this bl
ock
        previous declaration at C:\Go\src\runtime\runtime2.go:25
C:\Go\src\runtime\zruntime_defs_linux_arm.go:19: _Gcopystack redeclared in this
block
        previous declaration at C:\Go\src\runtime\runtime2.go:26
C:\Go\src\runtime\zruntime_defs_linux_arm.go:20: _Gscan redeclared in this block

        previous declaration at C:\Go\src\runtime\runtime2.go:28
C:\Go\src\runtime\zruntime_defs_linux_arm.go:20: too many errors

C:\Users\Henry\Documents\Projects\Go\src\has\hello>



On Monday, August 31, 2015 at 10:30:45 AM UTC+7, Dave Cheney wrote:

Dave Cheney

unread,
Aug 31, 2015, 4:40:04 AM8/31/15
to golang-nuts
How did you install Go? It looks like this was a zip file or compiled from source.

Henry Adi Sumarto

unread,
Aug 31, 2015, 5:38:30 AM8/31/15
to golang-nuts
I installed 1.5 from the binary distribution, but I had a build from source (version 1.4.2) before and removed it prior to installing 1.5. Do you think that there might be some left-overs from the 1.4.2? I thought I was pretty thorough with the removal.

I'll try to re-install 1.5 and see how it works. 


On Monday, August 31, 2015 at 3:40:04 PM UTC+7, Dave Cheney wrote:

Henry Adi Sumarto

unread,
Aug 31, 2015, 5:53:05 AM8/31/15
to golang-nuts
It was my bad. You're right. I removed Go, deleted the left-over folders, and reinstalled it. It works now.

I still think that the cross-compilation instructions should be put together with the "Effective Go" documentation.

Thanks again, Dave.

Nick Craig-Wood

unread,
Sep 1, 2015, 4:29:55 AM9/1/15
to golan...@googlegroups.com
On 31/08/15 04:30, Dave Cheney wrote:
> Yes it is possible. Here is a blog post I wrote last week on the subject.
>
> http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5

Another alternative is to use gox which works with go 1.5 (without using
-build-toolchain)

It is really good for cross compiling to lots of targets (eg if you are
doing a release build of a binary)

https://github.com/mitchellh/gox

--
Nick Craig-Wood <ni...@craig-wood.com> -- http://www.craig-wood.com/nick

Dave Cheney

unread,
Sep 1, 2015, 4:37:31 AM9/1/15
to golang-nuts
Or my own gb, which will work fine as a drop in replacement for the go tool (you don't need to migrate to a gb project, you can keep using GOPATH and go get).

Gb supports cross compilation and always caches the output of any compilation.

Thanks

Dave
Reply all
Reply to author
Forward
0 new messages