Go 1.5到1.6版本:不允许导入循环

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

Go 1.5 to 1.6: import cycle not allowed

问题

我正在尝试从Go 1.5.3迁移到Go 1.6,但在构建某些包时遇到了“不允许循环导入”错误。

例如,构建golint工具时,我遇到了以下错误:

不允许循环导入
包github.com/golang/lint/golint导入了flag
导入了errors
导入了runtime
导入了runtime/internal/atomic

这是我的本地环境有问题还是有办法修复这个问题?

go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/radek/Projekty/Go"
GORACE=""
GOROOT="/home/radek/Software/Go/go1.6"
GOTOOLDIR="/home/radek/Software/Go/go1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
英文:

I'm trying to migrate from Go 1.5.3 to Go 1.6 and for some packages I encounter "import cycle not allowed" error, when I'm trying to build them for 1.6 .

e.g for building the golint tool I'm getting:

import cycle not allowed
package github.com/golang/lint/golint
    imports flag
	imports errors
    imports runtime
	imports runtime/internal/atomic
    imports runtime

Is there eny problem in my local env or is there any way how to fix this?

go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/radek/Projekty/Go"
GORACE=""
GOROOT="/home/radek/Software/Go/go1.6"
GOTOOLDIR="/home/radek/Software/Go/go1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

答案1

得分: 5

我最近遇到了这个问题。这可能与我的环境变量设置错误有关。

运行 go version 命令,检查你是否使用了正确的 Go 发行版进行构建。

如果版本不是你期望的版本,请确保将 $GOROOT 和/或 $GOPATH 变量更新为正确的设置。

https://golang.org/doc/install

英文:

I had this happen to me the other day. It had something to do with my environment variables being setup wrong.

do go version and check that you are building with the expected go distribution.

If it's not the version you were expecting, make sure you update your $GOROOT and or $GOPATH variables to the correct settings.

https://golang.org/doc/install

答案2

得分: 1

这个错误是在有一个包自己导入自己时显示的。例如,在$GOPATH/src/github.com/myawesome/mistakes目录下,你有一个文件像这样:

package mistakes

import (
    "github.com/myawesome/mistakes"
)

func CreateComplicatedBugFromSimpleMistake(m mistakes.Mistake) {
    // done.
}

这就是我正在做的。如果你也遇到了这个问题,你应该知道如何解决它。

英文:

This error is what is shown when there is a package importing itself. For example, in $GOPATH/src/github.com/myawesome/mistakes, you have a file that like this:

package mistakes

import (
    "github.com/myawesome/mistakes"
)

func CreateComplicatedBugFromSimpleMistake(m mistakes.Mistake) {
    // done.
}

That was what I was doing. You should know how to solve it, if this is your case too.

答案3

得分: 0

比较 readlink -f $(which go)echo $GOROOT 的输出,如果它们不同,你应该设置 $GOROOT 指向你正在运行的 go 二进制文件的根目录,或者反之亦然。

英文:

Compare the output of readlink -f $(which go) and echo $GOROOT and if they are different, you should set $GOROOT to point to the root directory of the go binary you are running or vice versa.

huangapple
  • 本文由 发表于 2016年2月3日 12:31:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/35168558.html
匿名

发表评论

匿名网友

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

确定