Go无法检测到`sync`包。

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

Go does not detect `sync` package

问题

我收到了你的翻译请求。以下是你提供的代码的翻译:

我收到了 error: reference to undefined identifier ‘sync.Pool’ 的错误信息,而这段代码在 Playground 中是可以工作的。我应该怎么做?

package main

import (
  "fmt"
  "sync"
)

func main() {
  var wg sync.Pool
  fmt.Println(wg)
}

请注意,我只提供代码的翻译部分,不会回答关于翻译内容的问题。

英文:

I get error: reference to undefined identifier ‘sync.Pool’ message and this is working in Playground. What should I do?

package main

import (
  "fmt"
  "sync"
)

func main() {
  var wg sync.Pool
  fmt.Println(wg)
}

答案1

得分: 5

你没有安装正确版本的Go。sync.Pool只在Go 1.3中添加。尝试更新你的本地Go包,确认你正在运行1.3版本,然后再试一次。

英文:

You don't have the correct version of Go installed. sync.Pool was only added in Go 1.3. Try updating your local go package, verify you are running 1.3, and try again.

答案2

得分: 2

如果你是从源代码安装的Go,请检查$GOROOT$GOROOT_FINAL的引用:如果它们不同,你需要将GOROOT重置为GOROOT_FINAL

  • $GOROOT是未显式设置时已安装的二进制文件和脚本的默认值,默认为$GOROOT的值。
  • 如果你想在一个位置构建Go树,但在构建后将其移动到其他位置,请将$GOROOT_FINAL设置为最终位置。

从评论中可以看到,OP提到:

  • go version输出为:go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64
  • $GOROOT/pkg/linux_amd64/sync.a确实存在。

我建议确保$PATH包含$GOROOT/bin
JimB补充道:

  • 更具体地说,确保你的$PATH包含正确GOROOT$GOROOT/bin。我认为你安装了两个版本,这让事情更加混乱。
英文:

If you installed go from source, check what $GOROOT et ^$GOROOT_FINAL refer to: if they differ, you need to reset your GOROOT to GOROOT_FINAL.

> The value assumed by installed binaries and scripts when $GOROOT is not set explicitly.
It defaults to the value of $GOROOT.

> If you want to build the Go tree in one location but move it elsewhere after the build, set $GOROOT_FINAL to the eventual location.


From the comments, the OP mentions:

> go version prints out

go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64 

And $GOROOT/pkg/linux_amd64/sync.a does exist.

I recommended to make sure $PATH includes $GOROOT/bin
JimB added:

> to be more specific, make sure your $PATH contains $GOROOT/bin for the correct GOROOT. I think you have two installations making this more confusing.

huangapple
  • 本文由 发表于 2014年8月13日 03:27:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/25272506.html
匿名

发表评论

匿名网友

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

确定