问题描述:

I installed go on Windows. GOPATH is set to this:

 c:\go-workspace

I have file called login.go in this directory:

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

login.go contains this:

 package main

func main() {

fmt.Printf("login\n")

}

I tried the following to build:

 go build github.com/llnw/login/login

But I get this error:

 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)

What am I doing wrong?

网友答案:

From 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.

In your example, github.com/llnw/login/login looks neither like a package, nor a list of .go files. Probably you're looking for this:

go build github.com/llnw/login

Assuming that when you execute this command, the relative path github.com/llnw/login exists.

相关阅读:
Top