运行”go install”时出现错误。

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

Running go install results in error

问题

我在Windows上安装了Go。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

但是我得到了以下错误:

无法加载包:找不到任何位置的包“github.com/llnw/login/login”:
C:\Go\src\github.com\llnw\login\login(来自$GOROOT)
C:\go-workspace\src\github.com\llnw\login\login(来自$GOPATH)

我做错了什么?

英文:

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?

答案1

得分: 0

go build -h中:

用法:build [-o 输出] [-i] [构建标志] [包]

Build编译由导入路径指定的包,以及它们的依赖项,但不安装结果。

如果build的参数是一组.go文件,build将把它们视为指定单个包的源文件列表。

在你的例子中,github.com/llnw/login/login既不像一个包,也不像一组.go文件。可能你是在寻找这个:

go build github.com/llnw/login

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

英文:

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.

huangapple
  • 本文由 发表于 2016年10月23日 10:44:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/40199028.html
匿名

发表评论

匿名网友

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

确定