Maynard Robert
Maynard Robert

Reputation: 47

Go does not detect `sync` package

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)
}

Upvotes: 4

Views: 3798

Answers (2)

VonC
VonC

Reputation: 1327184

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.

Upvotes: 2

phayes
phayes

Reputation: 1570

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.

Upvotes: 5

Related Questions