Building Go on Cygwin

2,089 views
Skip to first unread message

bruno oliveira (zack)

unread,
Feb 19, 2012, 8:56:01 PM2/19/12
to golang-nuts
Hello all!

I've been trying to compile Go for my windows laptop for a few hours,
but no success. I was wondering if anyone has seen something similiar

Here's my set up:

> Windows 7 x64
> Cygwin with gcc-4.5.3, make 3-82, bison, binutils and the mingw64-x86_64 toolchain

GOROOT = /cygdrive/d/go
GOBIN = $GOROOT/bin
GOARCH = amd64
GOOS = windows

./all.bash runs with no problems at all up until this point: (building
lib9). I've been googling for a solution, but still no luck. Has
anyone seen this before ? Or have any idea of how to fix it?

Thank you a lot in advance.



%%%% making lib9 %%%%

make: Entering directory `/cygdrive/d/go/src/lib9'
quietgcc -I"/cygdrive/d/go/include" -ggdb -O2 -c "/cygdrive/d/go/src/
lib9/_p9dir.c"
quietgcc -I"/cygdrive/d/go/include" -ggdb -O2 -c "/cygdrive/d/go/src/
lib9/_exits.c"
cc1: warnings being treated as errors
/cygdrive/d/go/include/libc.h:313:0: error: "O_BINARY" redefined
/usr/include/sys/_default_fcntl.h:51:0: note: this is the location of
the previous definition
cc1: warnings being treated as errors
/cygdrive/d/go/include/libc.h:313:0: error: "O_BINARY" redefined
/usr/include/sys/_default_fcntl.h:51:0: note: this is the location of
the previous definition
../Make.clib:11: recipe for target `_p9dir.o' failed
make: *** [_p9dir.o] Error 1
make: *** Waiting for unfinished jobs....
../Make.clib:11: recipe for target `_exits.o' failed
make: *** [_exits.o] Error 1
make: Leaving directory `/cygdrive/d/go/src/lib9'

AllenDang

unread,
Feb 19, 2012, 11:16:35 PM2/19/12
to golang-nuts
The newest weekly release contains "all.bat" which makes it is very
easy to compile Go on Windows because it only depends on "gcc".

Make sure "gcc" in "Path", set GOROOT, GOBIN, GOARCH and GOOS, invoke
"all.bat" and everything should be done in few minutes.

On Feb 20, 9:56 am, "bruno oliveira (zack)"

minux

unread,
Feb 19, 2012, 11:25:37 PM2/19/12
to AllenDang, golang-nuts
On Mon, Feb 20, 2012 at 12:16 PM, AllenDang <alle...@gmail.com> wrote:
The newest weekly release contains "all.bat" which makes it is very
easy to compile Go on Windows because it only depends on "gcc".

Make sure "gcc" in "Path", set GOROOT, GOBIN, GOARCH and GOOS, invoke
These environment variables don't need to be set now. The dist tool is smart enough
to detect them. Just cd to src and then all.bat will do.

bruno oliveira (zack)

unread,
Feb 20, 2012, 7:29:57 AM2/20/12
to golang-nuts
Thank you for helping guys!

Just to make sure we're all on the same page...

I was trying to compile the build you get with "hg clone -u release
https://go.googlecode.com/hg/ go"
as if I were in linux (taking that I'm on cygwin... But I couldn't
find all.bat in there

So as for the weekly release, I'm getting this one: "gowinamd64_weekly.
2012-02-14.zip"
from "http://code.google.com/p/gomingw/downloads/list"

But with that I've got 2 issues, one of them I managed to solve:

Issue #1.

Whenever I tried to run all.bat from Windows CMD (or even when in bash/
cygwin) I was getting "Access Denied".
Actually... just by running "gcc" was getting me that. I would work if
I triggered it with "gcc-4",
so I'm guessing Windows won't follow the symlinks // the gcc file)

So within <CYGWIN_ROOT>\bin I renamed "gcc.exe" to "gcc.exe.bkp" and
created a batch file "gcc.bat"

REM gcc.bat
REM ======= Triggers gcc-4 properly ===========
D:\cygwin\bin\gcc-4.exe %*

Now I'm able to run GCC from Windows CMD/Prompt or Cygwin, however,
somehow I'm still being unlucky...

This is the STDOUT from the all.bat (run from Windows CMD, I've tried
the same thing using bash/cygwin,
but the output is almost the same). It fails at two points.

Could you please take a look? Thank you.


# Building C bootstrap tool.
cmd/dist
cc1: warnings being treated as errors
cmd/dist/build.c:19:16: error: unknown escape sequence: '\g'
cmd/dist/build.c:20:22: error: unknown escape sequence: '\g'
# Testing packages.
ok cmd/api 0.252s
? cmd/cgo [no test files]
ok cmd/fix 3.728s
? cmd/go [no test files]
? cmd/godoc [no test files]
ok cmd/gofmt 0.403s
? cmd/vet [no test files]
? cmd/yacc [no test files]
ok archive/tar 0.142s
ok archive/zip 0.370s
ok bufio 0.140s
ok bytes 0.226s
ok compress/bzip2 0.373s
ok compress/flate 4.987s
ok compress/gzip 0.213s
ok compress/lzw 0.514s
ok compress/zlib 0.610s
ok container/heap 0.164s
ok container/list 0.081s
ok container/ring 0.454s
? crypto [no test files]
ok crypto/aes 0.149s
ok crypto/cipher 0.207s
ok crypto/des 0.161s
ok crypto/dsa 0.121s
ok crypto/ecdsa 0.260s
ok crypto/elliptic 0.259s
ok crypto/hmac 0.111s
ok crypto/md5 0.193s
ok crypto/rand 0.255s
ok crypto/rc4 0.152s
ok crypto/rsa 0.476s
ok crypto/sha1 0.177s
ok crypto/sha256 0.139s
ok crypto/sha512 0.170s
ok crypto/subtle 0.177s
ok crypto/tls 0.578s
ok crypto/x509 0.817s
? crypto/x509/pkix [no test files]
ok database/sql 0.559s
ok database/sql/driver 0.045s
ok debug/dwarf 0.317s
ok debug/elf 0.165s
ok debug/gosym 0.180s
ok debug/macho 0.325s
ok debug/pe 0.076s
ok encoding/ascii85 0.140s
ok encoding/asn1 0.184s
ok encoding/base32 0.244s
ok encoding/base64 0.074s
ok encoding/binary 0.406s
ok encoding/csv 0.214s
ok encoding/gob 0.362s
ok encoding/hex 0.175s
ok encoding/json 0.321s
ok encoding/pem 0.150s
ok encoding/xml 0.094s
ok errors 0.230s
ok exp/ebnf 0.084s
ok exp/ebnflint 0.175s
ok exp/gotype 0.741s
ok exp/html 0.516s
ok exp/norm 1.929s
ok exp/proxy 0.465s
ok exp/terminal 0.226s
ok exp/types 0.531s
ok exp/utf8string 0.233s
ok exp/winfsnotify 0.227s
? exp/wingui [no test files]
ok expvar 0.326s
ok flag 0.127s
ok fmt 0.531s
ok go/ast 0.089s
ok go/build 0.809s
ok go/doc 0.552s
ok go/parser 0.139s
ok go/printer 0.872s
ok go/scanner 0.103s
ok go/token 0.202s
? hash [no test files]
ok hash/adler32 0.307s
ok hash/crc32 0.333s
ok hash/crc64 0.260s
ok hash/fnv 0.321s
ok html 1.190s
ok html/template 0.643s
ok image 1.506s
ok image/color 0.125s
ok image/draw 0.165s
? image/gif [no test files]
ok image/jpeg 0.864s
ok image/png 0.261s
ok index/suffixarray 0.133s
ok io 0.252s
ok io/ioutil 0.083s
ok log 0.204s
ok log/syslog 0.545s
ok math 0.104s
ok math/big 1.369s
ok math/cmplx 0.069s
ok math/rand 0.696s
ok mime 0.243s
ok mime/multipart 0.427s
ok net 1.334s
ok net/http 7.608s
--- FAIL: TestEnvOverride (0.14 seconds)
host_test.go:66: for key "cwd" got "/cygdrive/d/go/src/pkg/net/
http/cgi"; expected "D:\\go\\src\\pkg\\net\\http\\cgi"
FAIL
FAIL net/http/cgi 0.478s
ok net/http/fcgi 0.227s
ok net/http/httptest 0.289s
ok net/http/httputil 0.553s
? net/http/pprof [no test files]
ok net/mail 0.796s
ok net/rpc 0.495s
ok net/rpc/jsonrpc 0.600s
ok net/smtp 0.740s
ok net/textproto 0.142s
ok net/url 0.265s
ok old/netchan 1.413s
ok old/regexp 0.135s
ok old/template 0.139s
ok os 0.173s
ok os/exec 1.154s
ok os/signal 0.702s
ok os/user 34.427s
ok path 0.251s
ok path/filepath 0.058s
ok reflect 0.090s
ok regexp 0.184s
ok regexp/syntax 2.322s
ok runtime 6.714s
? runtime/cgo [no test files]
ok runtime/debug 0.044s
ok runtime/pprof 0.813s
ok sort 0.719s
ok strconv 0.155s
ok strings 0.145s
ok sync 0.232s
ok sync/atomic 0.242s
? syscall [no test files]
? testing [no test files]
? testing/iotest [no test files]
ok testing/quick 0.111s
ok text/scanner 0.057s
ok text/tabwriter 0.312s
ok text/template 0.072s
ok text/template/parse 0.072s
--- FAIL: TestTicker (0.17 seconds)
tick_test.go:29: 10 10ms ticks took 168.0096ms, expected [80ms,
120ms]
FAIL
FAIL time 2.334s
ok unicode 0.080s
ok unicode/utf16 0.091s
ok unicode/utf8 0.150s
? unsafe [no test files]













On 20 fev, 02:25, minux <minux...@gmail.com> wrote:

Aram Hăvărneanu

unread,
Feb 20, 2012, 7:41:55 AM2/20/12
to bruno oliveira (zack), golang-nuts
You need a native GCC, like mingw, not cygwin.

--
Aram Hăvărneanu

bruno oliveira (zack)

unread,
Feb 20, 2012, 7:48:43 AM2/20/12
to golang-nuts
Just one question:

When I got my cygwin (with setup.exe),
I also issued the install of the mingw toolchain (mingw64-x86_64)
along with make, gcc-4, bison, awk and binutils. That won't do?

Should I get the mingw from the official http://www.mingw.org/ site ?

Thank you very much!

Aram Hăvărneanu

unread,
Feb 20, 2012, 7:54:22 AM2/20/12
to bruno oliveira (zack), golang-nuts
> When I got my cygwin (with setup.exe),
> I also issued the install of the mingw toolchain (mingw64-x86_64)
> along with make, gcc-4, bison, awk and binutils. That won't do?

Cygwin is a sign of impeding pestilence. I avoid it at all cost. If
there's nothing forcing you to use it, I recommend deleting it from
your hard drive, until it's too late.

Maybe the mingw from cygwin works, maybe not.

> Should I get the mingw from the official http://www.mingw.org/ site ?

That would be my recommendation, yes.

--
Aram Hăvărneanu

bruno oliveira (zack)

unread,
Feb 20, 2012, 8:27:07 AM2/20/12
to golang-nuts
Sorry for the silly question, but what are the pre-requisities to
build it on windows?

The README file won't mention it and the doc/install.html still thave
that Windows as a TO-DO...

I just did as said: Dropped my cygwin and got the "official" mingw
toolchain. I can properly run GCC and Make from my windows prompt
without any error messages. All variables are set all right, but
still:

D:\>cd go\src

D:\go\src>all.bat
# Building C bootstrap tool.
cmd/dist

// Here it ends, no warnings, no error messages... nothing at all. I'm
kinda lost now...



On 20 fev, 10:54, Aram Hăvărneanu <ara...@mgk.ro> wrote:
> > When I got my cygwin (with setup.exe),
> > I also issued the install of the mingw toolchain (mingw64-x86_64)
> > along with make, gcc-4, bison, awk and binutils. That won't do?
>
> Cygwin is a sign of impeding pestilence. I avoid it at all cost. If
> there's nothing forcing you to use it, I recommend deleting it from
> your hard drive, until it's too late.
>
> Maybe the mingw from cygwin works, maybe not.
>
> > Should I get the mingw from the officialhttp://www.mingw.org/site ?

Aram Hăvărneanu

unread,
Feb 20, 2012, 8:50:41 AM2/20/12
to bruno oliveira (zack), golang-nuts
> Sorry for the silly question, but what are the pre-requisities to
> build it on windows?

Mercurial: http://mercurial.selenic.com
GCC: http://www.mingw.org

Make sure gcc.exe is in your path.

C:\>hg clone -u weekly https://go.googlecode.com/hg/ go
requesting all changes
adding changesets
adding manifests
adding file changes
added 12160 changesets with 47326 changes to 6921 files (+4 heads)
updating to branch default
3256 files updated, 0 files merged, 0 files removed, 0 files unresolved

C:\>cd go\src

C:\go\src>all.bat
[ ... output ... ]
ALL TESTS PASSED

---
Installed Go for windows/386 in C:\go
Installed commands in C:\go\bin

C:\go\src>go version
go version weekly.2012-02-14 +43cf9b39b647

The environment is:

C:\>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure
--enable-languages=c,c++,ada,fortran,objc,obj-c++
--disable-sjlj-exceptions --with-dwarf2 --enable-shared
--enable-libgomp --disable-win32-registry --enable-libstdcxx-debug
--enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)

C:\>hg --version
Mercurial Distributed SCM (version 1.9.1)
(see http://mercurial.selenic.com for more information)

Copyright (C) 2005-2011 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Also tried a amd64 build, that also works.

--
Aram Hăvărneanu

Mike Rosset

unread,
Feb 20, 2012, 9:51:18 AM2/20/12
to bruno oliveira (zack), golang-nuts
> Sorry for the silly question, but what are the pre-requisities to
> build it on windows?

mingw and hg native for windows.

http://www.mingw.org/wiki/InstallationHOWTOforMinGW

http://mercurial.selenic.com/wiki/Download#Windows

then add C:\MinGW\bin to your PATH.

after that use only cmd.exe and use all.bat or make.bat

bruno oliveira (zack)

unread,
Feb 20, 2012, 9:59:30 AM2/20/12
to golang-nuts
Thank you very much!

All is set now!

# sync -cpu=10
ok sync 0.439s
.
ALL TESTS PASSED

---
Installed Go for windows/386 in D:\go
Installed commands in D:\go\bin

D:\go\src>cd \

D:\>go run hello.go
>> Hello Go world. It works.

D:\>
>     (seehttp://mercurial.selenic.comfor more information)
Reply all
Reply to author
Forward
0 new messages