5

I recently started trying go to program some web based applications. At first, everything went fine, until I wanted to cross compile a binary for a different platform. I'm running MacOS and I wanted to compile a binary for linux, so I changed GOOS to linux and GOARCH to amd64. Since then, I always get the error message

go tool: no such tool "compile"

I'm using GoClipse, but running the compile manually by

go install hello.go

I get the same error. When changing back to compiling for darwin architecture, I get the same error now, so basically I'm totally unable to compile any code written in Go at the moment.

Benjamin Scharbau
  • 2,028
  • 1
  • 16
  • 33
  • 1
    How did you install Go (source? installer? Homebrew) and did you install the cross-compilers as well? As per @OneofOne's answer, if you have cgo dependencies then cross-compiling becomes complicated (oft. easier to just spin up a small Vagrant box). – elithrar Sep 02 '15 at 03:34
  • cross compiling try [gox](https://github.com/mitchellh/gox) ? – holys Sep 02 '15 at 04:49
  • Here is the line printing this error : https://github.com/golang/go/blob/21ec72c2ca5168f3f10b4594a553b3a038c8df29/src/cmd/go/tool.go#L61 – HectorJ Sep 02 '15 at 09:47
  • Can you give the full output of `go env` ? – HectorJ Sep 02 '15 at 09:48

5 Answers5

2

I installed it via the binary packages provided by google. In the end I actually got it back to work by just reinstalling it. Sometimes I'm just blind to the easy solution.

After that, I succeeded in cross compiling for linux machine after compiling the necessary cross-compilers by running env GOOS=linux GOARCH=arm GOROOT_BOOTSTRAP=/usr/local/go ./make.bash --no-clean from the Go sources directory.

Thanks for all you efforts, sorry to have kept you busy on such a simple matter.

Benjamin Scharbau
  • 2,028
  • 1
  • 16
  • 33
1

You have the wrong x64 or x386 package installed most likely. I had 32 installed running 64 bit. Reinstall fixed. Good luck.

Andy
  • 966
  • 11
  • 16
0

You might be able to get away with that if you install Go 1.5, however if you use anything that depends on cgo, you will have to install a cross-compiler linker or install Linux on a virtual machine to be able to cross compile for Linux.

OneOfOne
  • 95,033
  • 20
  • 184
  • 185
0

In my case is due to the fact that GOPATH and GOROOT are not set correctly, maybe you can check go env. Here is a discussion may be useful.

Kehe CAI
  • 1,161
  • 12
  • 18
0

The way I figured-out what file is read and caused Go to look for the compile binary in the wrong place can be solved using: $ strace go tool -n compile 2>&1 |grep openat

openat(AT_FDCWD, "/home/nwaizer/.config/go/env", O_RDONLY|O_CLOEXEC) = 3

In that file, the IDE Goland, add a path to some project, causing the havoc.

Niv Waizer
  • 31
  • 4