英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论