Go:导入hello world时出现错误

huangapple go评论86阅读模式
英文:

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

英文:

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.

huangapple
  • 本文由 发表于 2013年2月13日 02:24:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/14839205.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定