英文:
Go: error on import in hello world
问题
我的测试程序test.go
:
package main
import "fmt"
func main() {
fmt.Printf("Hello\n")
}
运行go run test.go
会出现错误:
# io
pack: 无法打开 $WORK/io/_obj/_go_.6
# strconv
pack: 无法打开 $WORK/strconv/_obj/_go_.6
环境:
go version devel +715674f61ae8 Tue Jan 29 13:34:18 2013 -0800 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/home/igord/incub/web"
GOROOT="/opt/go"
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
但是我从go网站上下载了这个版本(特色)RELEASE 1.0.3!
英文:
My test program test.go
:
package main
import "fmt"
func main() {
fmt.Printf("Hello\n")
}
Running this go run test.go
finishes with errors:
# io
pack: cannot open $WORK/io/_obj/_go_.6
# strconv
pack: cannot open $WORK/strconv/_obj/_go_.6
Environment:
go version devel +715674f61ae8 Tue Jan 29 13:34:18 2013 -0800 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/home/igord/incub/web"
GOROOT="/opt/go"
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
But I downloaded this version from (featured) RELEASE 1.0.3 on the go site!
答案1
得分: 1
由评论中的各种解决方法,但为了记录:安装Go的二进制发行版到非默认位置需要正确设置$GOROOT
和$GOPATH
。
- 入门指南:安装Go工具
- 相关链接:https://stackoverflow.com/questions/7970390/what-should-be-the-values-of-gopath-and-goroot
英文:
Resolved by various in comments, but for the record: installing a binary distribution of Go to a location other than the default requires setting $GOROOT
and $GOPATH
correctly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论