windows.go – no go!

Standard
Download PDF

Playing with Go I found today an interesting bug – if a file named windows.go Go compiler doesn’t compile it.

I made a simple test – a new project and placed in it the only file named windows.go:

$ mkdir g1
$ cd g1
$ export GOPATH=$(pwd)
$ cat >windows.go
package main

import "fmt"

func main() {
  fmt.Println("Hello world")
}

If you compile this simple program, the expected output is “Hello world”. At least I expect it. But no way – it won’t compile:

$ go build
can't load package: package .: no buildable Go source files in /src/g1

And debug output won’t help too:

$ go build -work -x
WORK=/var/folders/9p/bnyfm2md0q5_j4wb3zh9_yq00000gn/T/go-build620868854
can't load package: package .: no buildable Go source files in /src/g1

The only thing that helps is to rename file.

$ mv windows.go macosx.go
$ go build
$ ls
g1*       macosx.go
$ ./g1
Hello, world

But if you are Linux fan, don’t start loughing! linux.go is the same way no go, as windows.go

Download PDF

Leave a Reply

Your email address will not be published. Required fields are marked *