运行go install导致错误

时间:2016-10-23 02:45:00

标签: windows go build

我安装了Windows。 GOPATH设置为:

    c:\go-workspace

我在这个目录中有一个名为login.go的文件:

    C:\go-workspace\src\github.com\llnw\login

login.go包含:

    package main
    func main() {
      fmt.Printf("login\n")
    }

我尝试了以下内容来构建:

    go build github.com/llnw/login/login

但是我收到了这个错误:

    can't load package: package github.com/llnw/login/login: cannot find package "github.com/llnw/login/login" in any of:
    C:\Go\src\github.com\llnw\login\login (from $GOROOT)
    C:\go-workspace\src\github.com\llnw\login\login (from $GOPATH)

我做错了什么?

1 个答案:

答案 0 :(得分:0)

来自go build -h

usage: build [-o output] [-i] [build flags] [packages]

Build compiles the packages named by the import paths,
along with their dependencies, but it does not install the results.

If the arguments to build are a list of .go files, build treats
them as a list of source files specifying a single package.

在您的示例中,github.com/llnw/login/login看起来既不是包,也不是.go文件列表。可能你正在寻找这个:

go build github.com/llnw/login

假设执行此命令时,相对路径github.com/llnw/login存在。