Re: How will I can compile to another architecture from windows 64 bit?

1,691 views
Skip to first unread message

brainman

unread,
Apr 14, 2013, 7:28:36 PM4/14/13
to golan...@googlegroups.com
This http://code.google.com/p/go-wiki/wiki/WindowsCrossCompiling is what I do to build windows binaries on linux. Perhaps, you will find it useful.

Alex

Aleksey Levykh

unread,
Apr 14, 2013, 8:44:21 PM4/14/13
to golan...@googlegroups.com
Thanks Alex!

I read this tutorial, but I don't understand linux command promt. How I can repeat this commands on my win7 machine?
Where I will need set this constant GOOS and GOARCH?

Sorry for my stupid question..

понедельник, 15 апреля 2013 г., 6:28:36 UTC+7 пользователь brainman написал:

brainman

unread,
Apr 14, 2013, 10:56:49 PM4/14/13
to golan...@googlegroups.com
On Monday, 15 April 2013 10:44:21 UTC+10, Aleksey Levykh wrote:
... How I can repeat this commands on my win7 machine?

Please, try to translate my instructions and tell us where you get stuck. Will help you.
 
Where I will need set this constant GOOS and GOARCH?

These are environment variables. You can set them like this:

set GOOS=linux

on windows. You could also put them in a batch file, so you do not need to run them again and again. For example, this

set GOROOT=c:\mygo
set GOPATH=c:\mygopath
set PATH=%PATH%;c:\mingw\bin;%GOROOT%\bin
cd %GOPATH%\src
cmd

is how I start a command prompt with all my Go environment setup. You could have many batch files like that with different environment settings.

Alex

lu dongping

unread,
Apr 14, 2013, 11:29:02 PM4/14/13
to brainman, golang-nuts
I tried on OSX 10.8.3 with go 1.1 beta2 .
It seems that the go compile does not show respect to GOOS and GOARCH.

$ echo $GOOS
windows

$ echo $GOARCH
386

$ go build -o hello.exe hello.go

$ file hello.exe
hello.exe: Mach-O 64-bit executable x86_64





Alex

--
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.
 
 

brainman

unread,
Apr 14, 2013, 11:44:27 PM4/14/13
to golan...@googlegroups.com, brainman
On Monday, 15 April 2013 13:29:02 UTC+10, outersky wrote:
I tried on OSX 10.8.3 with go 1.1 beta2 .
It seems that the go compile does not show respect to GOOS and GOARCH.


I suspect you didn't "export" your GOOS and GOARCH. Having them defined in your current shell is not enough for new process (go) to see them. I am not sure what the command is on OSX to do that, but on linux I do "export GOOS=xxxx".

Alex

lu dongping

unread,
Apr 15, 2013, 12:18:02 AM4/15/13
to brainman, golang-nuts
aha, yes, it works now .
Thanks.



--

Dobrosław Żybort

unread,
Apr 15, 2013, 5:28:26 AM4/15/13
to golan...@googlegroups.com, brainman
Try goxc (Cross compiler for Go, written in Go):
http://www.laher.net.nz/goxc/

Aleksey Levykh

unread,
Apr 15, 2013, 9:03:10 AM4/15/13
to golan...@googlegroups.com
Thank you very much for your answers! I understand - it's not my level and I can't to repeat yours recommendations.

Of course, I tried, but I recieved error "go build runtime: windows/386 must be bootstrapped using make.bash" or "gcc" is not an internal or external command, operable program or batch file.

I'd rather wait to be a simpler mechanism compilation like this (I hope this will ever happen):
>go build OS=xxx ARCH=xxx source_dir target_dir

Thank you again and please do not waste your time to me!
Topic closed.

Dobrosław Żybort

unread,
Apr 15, 2013, 9:17:44 AM4/15/13
to golan...@googlegroups.com
https://github.com/laher/goxc#more-options

To build toolchains for linux x86 and x64:
goxc -t -os=linux -arch="amd64 386"

now to build your code for them:
goxc -os=linux -arch="amd64 386" -d="destination/directory" path/to/app/dir

Is that not what you want?

Aleksey Levykh

unread,
Apr 16, 2013, 10:38:23 AM4/16/13
to golan...@googlegroups.com
Yeah!! :) Dobrosław Żybort, Thank You very much!

I tried all possible wrong choices and find one that works for me!

Small instruction for newbies (like me :D [Windows 7 64 bit]) :
  1. Download and install needed for you "get tools" https://code.google.com/p/go-wiki/wiki/GoGetTools (hg and git - important, usually)
  2. Download and install MinGW http://tdm-gcc.tdragon.net/ [This is unofficial builds, but works for me and support 32/64 bits Windows] !Don't forget set PATH variables!
  3. Go to drive (eg e:) where you planning install Go and type WIN+R>cmd
  4. e:\>hg clone -u release https://code.google.com/p/go (version 1.03)
  5. e:\>cd go\src
  6. e:\>all.bat and wait ~1 min
  7. Add manually GOBIN, GOROOT, and others Go variables http://golang.org/doc/install/source#environment (you can check current env e:\>go env or simple type e:\>set )
  8. Install goxc e:\>go get github.com/laher/goxc https://github.com/laher/goxc
  9. Build toolchains for all platforms e:\>goxc -t or needed for you only and cross-compiling works very well (read last message from Dobrosław Żybort)
  10. That's all :))
Good day, guys!

Dobrosław Żybort

unread,
Apr 16, 2013, 12:10:21 PM4/16/13
to Aleksey Levykh, golang-nuts
Glad I could help.

Oh, and don't forget that cross compilation still don't work with programs/packages using cgo:
http://code.google.com/p/go/issues/detail?id=4714


Dobrosław Żybort


2013/4/16 Aleksey Levykh <aleksey...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/oRf-vgDjBLI/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages