英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论