Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go does not detect `sync` package

Tags:

go

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)
}
like image 431
Maynard Robert Avatar asked Mar 18 '23 18:03

Maynard Robert


2 Answers

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.

like image 66
phayes Avatar answered Mar 29 '23 08:03

phayes


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.

like image 34
VonC Avatar answered Mar 29 '23 08:03

VonC