go工具:没有这样的工具“compile”

huangapple go评论99阅读模式
英文:

go tool: no such tool "compile"

问题

最近我开始尝试编写一些基于Web的应用程序。起初一切都很顺利,直到我想要为不同的平台交叉编译一个二进制文件。我使用的是MacOS,想要为Linux编译一个二进制文件,所以我将GOOS改为linuxGOARCH改为amd64。从那时起,我一直收到以下错误信息:

go tool: no such tool "compile"

我正在使用GoClipse,但是手动运行编译命令

go install hello.go

我得到了相同的错误。当我改回编译为darwin架构时,现在我也得到了相同的错误,所以基本上我现在完全无法编译任何用Go编写的代码。

英文:

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.

答案1

得分: 2

我通过谷歌提供的二进制包进行了安装。最后,我只是重新安装它,实际上就解决了问题。有时候,我对简单的解决方案视而不见。

在那之后,我成功地进行了交叉编译,为 Linux 机器编译了必要的交叉编译器,通过在 Go 源代码目录中运行 env GOOS=linux GOARCH=arm GOROOT_BOOTSTRAP=/usr/local/go ./make.bash --no-clean

感谢你的努力,很抱歉让你在这样一个简单的问题上忙碌。

英文:

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.

答案2

得分: 1

你可能安装了错误的x64或x386软件包。我之前安装了32位的软件包,但是在64位系统上运行。重新安装解决了问题。祝你好运。

英文:

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

答案3

得分: 0

你可以尝试安装Go 1.5来解决这个问题,但是如果你使用了依赖于cgo的任何内容,你将需要安装一个交叉编译链接器,或者在虚拟机上安装Linux以进行Linux的交叉编译。

英文:

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.

答案4

得分: 0

在我的情况下,由于GOPATH和GOROOT没有正确设置,也许你可以检查go env这里的讨论可能会有用。

英文:

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.

答案5

得分: 0

我找出了哪个文件被读取并导致Go在错误的位置查找编译二进制文件的方法,可以使用以下命令解决:
$ strace go tool -n compile 2>&1 |grep openat

在那个文件中,IDE Goland添加了一个项目路径,导致了混乱。

英文:

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.

huangapple
  • 本文由 发表于 2015年9月2日 10:47:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/32343875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定