doupao6698 2015-01-06 23:40
浏览 427
已采纳

继续安装:“无法加载软件包”(即使设置了GOPATH)

I'm just getting started with the Go programming language and installed Go using the Windows installer from the website. I tested installation by using go run hello.go and that works. The problem comes when I try to build my first program:

$ echo $GOROOT
C:\Go\
$ echo $GOPATH
/cygdrive/c/Users/Paul/Documents/Home/go
mkdir -p $GOPATH/src/hello

Inside that directory I have a simple hello.go program:

package main

import "fmt"

func main() {
    fmt.Printf("Hello, world.
")
}

The problem comes when I try to build and install:

$ go install hello
can't load package: package hello: cannot find package "hello" in any of:
    C:\Go\src\hello (from $GOROOT)
    \cygdrive\c\Users\Paul\Documents\Home\go\src\hello (from $GOPATH)
  • 写回答

1条回答 默认 最新

  • dongxiang7276 2015-01-07 02:37
    关注

    GOPATH environment variable must contain valid path.

    \cygdrive\c\Users\Paul\Documents\Home\go\src\hello is not a valid path on Windows.

    Try setting GOPATH=c:\Users\Paul\Documents\Home\go instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?