Go does not detect the `sync` package

I get a message error: reference to undefined identifier ‘sync.Pool’

and it works in the Playground. What should I do?

package main

import (
  "fmt"
  "sync"
)

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

      

+3


source to share


2 answers


If you installed go from source , check what $GOROOT

et ^ refers to $GOROOT_FINAL

: if they differ, you need to reset your GOROOT

to GOROOT_FINAL

.

The value accepted by the installed binaries and scripts when $GOROOT

not explicitly specified.
The default is $GOROOT

.

If you want to build the Go tree in one location, but move it to a different location after building, set it $GOROOT_FINAL

to a possible location.


From comments the OP points out:

go version

deduces



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

      

And $GOROOT/pkg/linux_amd64/sync.a

there is.

I recommended to $PATH

include $GOROOT/bin

JimB add:

to make sure your $PATH

contains $GOROOT/bin

for the correct one GOROOT

. I think you have two settings that make this more confusing.

+1


source


You don't have the correct version of Go. sync.Pool

was only added in Go 1.3. Try updating your local go package, make sure you are using 1.3 and try again.



+5


source







All Articles