构建.go包时发生致命错误。

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

Fatal error when building .go package

问题

我正在尝试安装一个Go包。我克隆了这个包,并运行以下命令来构建它:

$go get -v -d

正在获取 https://golang.org/x/net/publicsuffix?go-get=1
正在解析元标签 https://golang.org/x/net/publicsuffix?go-get=1 (状态码 200)
获取 "golang.org/x/net/publicsuffix":在 https://golang.org/x/net/publicsuffix?go-get=1 找到元标签 main.metaImport{Prefix:"golang.org/x/net", VCS:"git", RepoRoot:"https://go.googlesource.com/net"}
获取 "golang.org/x/net/publicsuffix":正在验证非权威的元标签
正在获取 https://golang.org/x/net?go-get=1
正在解析元标签 https://golang.org/x/net?go-get=1 (状态码 200)
golang.org/x/net (下载)

$go build *.go
# github.com/moul/http2curl
gccgo: 错误: $HOME/go/src/github.com/moul/http2curl/http2curl.go: 没有那个文件或目录
gccgo: 致命错误: 没有输入文件
编译终止。
# github.com/pkg/errors
gccgo: 错误: $HOME/go/src/github.com/pkg/errors/errors.go: 没有那个文件或目录
gccgo: 错误: $HOME/go/src/github.com/pkg/errors/stack.go: 没有那个文件或目录
gccgo: 致命错误: 没有输入文件
编译终止。
# golang.org/x/net/publicsuffix
gccgo: 错误: $HOME/go/src/golang.org/x/net/publicsuffix/list.go: 没有那个文件或目录
gccgo: 错误: $HOME/go/src/golang.org/x/net/publicsuffix/table.go: 没有那个文件或目录
gccgo: 致命错误: 没有输入文件
编译终止。

我尝试将 github.com/moul/http2curl 克隆到 $HOME/go/src/github.com/moul/http2curl,并且 http2curl.go 文件确实在指定的路径中,但仍然显示"没有那个文件或目录"。我该如何构建它?

英文:

I'm trying to install a go package. I cloned the package, ran the following commands to build it:

$go get -v -d

Fetching https://golang.org/x/net/publicsuffix?go-get=1
Parsing meta tags from https://golang.org/x/net/publicsuffix?go-get=1 (status code 200)
get "golang.org/x/net/publicsuffix": found meta tag main.metaImport{Prefix:"golang.org/x/net", VCS:"git", RepoRoot:"https://go.googlesource.com/net"} at https://golang.org/x/net/publicsuffix?go-get=1
get "golang.org/x/net/publicsuffix": verifying non-authoritative meta tag
Fetching https://golang.org/x/net?go-get=1
Parsing meta tags from https://golang.org/x/net?go-get=1 (status code 200)
golang.org/x/net (download)

$go build *.go
# github.com/moul/http2curl
gccgo: error: $HOME/go/src/github.com/moul/http2curl/http2curl.go: No such file or directory
gccgo: fatal error: no input files
compilation terminated.
# github.com/pkg/errors
gccgo: error: $HOME/go/src/github.com/pkg/errors/errors.go: No such file or directory
gccgo: error: $HOME/go/src/github.com/pkg/errors/stack.go: No such file or directory
gccgo: fatal error: no input files
compilation terminated.
# golang.org/x/net/publicsuffix
gccgo: error: $HOME/go/src/golang.org/x/net/publicsuffix/list.go: No such file or directory
gccgo: error: $HOME/go/src/golang.org/x/net/publicsuffix/table.go: No such file or directory
gccgo: fatal error: no input files
compilation terminated.

I tried cloning github.com/moul/http2curl to $HOME/go/src/github.com/moul/http2curl and the http2curl.go file is exactly in the path specified and yet it still says No such file or directory.
How do I build this?

答案1

得分: 1

我不确定纯粹的 go get -v -d 命令会得到什么结果,但你应该指定你想要安装的包。
所以你应该这样做:

$go get github.com/moul/http2curl

不带 -d 标志,这将为你下载并安装 http2curl 包。但如果你使用 -d 标志,你可以通过首先进入包的目录来安装该包。

$cd $GOPATH/src/github.com/moul/http2curl

然后运行构建命令(不带 *.go)。

$go build

英文:

I'm not sure what plain go get -v -d gets you but you should specify the package(s) that you want to install.
So what you should do is something like this:

$go get github.com/moul/http2curl

Without the -d flag this should download and install the package http2curl for you. But if you use the -d flag, you can install the package by first moving to the package's directory.

$cd $GOPATH/src/github.com/moul/http2curl

And then running build (without *.go).

$go build

huangapple
  • 本文由 发表于 2017年3月19日 18:35:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/42885573.html
匿名

发表评论

匿名网友

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

确定