dsyk33753 2018-09-03 14:13
浏览 254

无法编译Go文件-“初始化失败…在此块中重新声明了xxxx”

I am new in Go and I follow the instructions in the website and the youtube video I am getting the follow errors when I run go build hello.go:

go: disabling cache (/home/myuser/.cache/go-build) due to initialization failure: open /home/myuser/.cache/go-build/log.txt: permission denied
# runtime
/usr/local/go/src/runtime/map.go:64:2: bucketCntBits redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:64:18
/usr/local/go/src/runtime/map.go:65:2: bucketCnt redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:65:23
/usr/local/go/src/runtime/map.go:69:2: loadFactorNum redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:69:18
/usr/local/go/src/runtime/map.go:70:2: loadFactorDen redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:70:18
/usr/local/go/src/runtime/map.go:76:2: maxKeySize redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:76:17
/usr/local/go/src/runtime/map.go:77:2: maxValueSize redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:77:17
/usr/local/go/src/runtime/map.go:82:2: dataOffset redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:85:4
/usr/local/go/src/runtime/map.go:91:2: empty redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:91:19
/usr/local/go/src/runtime/map.go:92:2: evacuatedEmpty redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:92:19
/usr/local/go/src/runtime/map.go:93:2: evacuatedX redeclared in this block
    previous declaration at /usr/local/go/src/runtime/hashmap.go:93:19
/usr/local/go/src/runtime/map.go:93:2: too many errors

It wrote permission denied but I tried to run it with sudo go build and it also failed with:

sudo: go: command not found

I am working on Ubuntu 16.4. My go file hello.go is in $HOME/Desktop/go/src/hello.

My file $HOME/myuser/.profile contains:
PATH="$HOME/bin:$HOME/.local/bin:$PATH:/usr/local/go/bin"

  • 写回答

1条回答 默认 最新

  • duanliang789262 2018-09-03 14:59
    关注

    Gopath

    The GOPATH environment variable lists places to look for Go code.
    On Unix, the value is a colon-separated string. On Windows, the value 
    is a semicolon-separated string. On Plan 9, the value is a list.
    
    GOPATH must be set to get, build and install packages outside the standard Go tree.
    Use tool like dep to segregate your different go project, maintaining your project dependencies. 
    

    Goroot

     The Go binary distributions assume they will be installed in /usr/local/go (or c:\Go under Windows), but it is possible to install 
    the Go tools to a different location. In this case you must set the 
    GOROOT environment variable to point to the directory in which it was installed.
    

    so its always preferred to make your own gopath for compiling your code. GOPATH is for your own go projects / 3rd party libraries (downloaded with "go get").

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog