【发布时间】:2014-03-24 00:55:00
【问题描述】:
我的问题与this 非常相似,不同的是我有最佳答案指出的目录层次结构,但我仍然遇到同样的问题,为什么?
$ echo $GOROOT
/usr/local/go
$ echo $GOPATH
/home/mitchell/go
$ cat /home/mitchell/go/src/main.go
package main
import "comment/create"
func main() { }
$ cat /home/mitchell/go/src/comment/create/***.go(bunch of go files)
package create
$ go build main.go
main.go:3:8: import "comment/create": cannot find package
【问题讨论】:
-
它适用于我的电脑。我建议运行
go env和go build -x main.go以获得更多线索。 -
也许是权限?放置 go build 的输出
-
main.go应该在src/comment/main.go中 - 即它需要在包本身中(“comment”或“mypackage123”)。同时发布go env的输出。 -
@elithrar,虽然我同意
main.go不应该位于src/main.go上,但这并不能解释编译失败。 -
你导出了 $GOPATH 吗?不导出,go就不捡了。
标签: go