我有基于样本项目设置此文章。这是我的目录结构:goloang/└── fooproject └── src ├── foo │ └── foo.go └── fooer └── fooer.go我已经设置了 GOTPATH$ echo $GOPATH/Users/Bharat/Dev/golang/fooproject我正在尝试运行,foor.go但即使它存在于GOPATHie in引用的位置中,我也会收到找不到包错误src/foo。这是我运行它的方式:$ pwd/Users/Bharat/Dev/goloang/fooproject/src/fooer$ go run fooer.go fooer.go:4:3: cannot find package "foo" in any of: /usr/local/go/src/foo (from $GOROOT) /Users/Bharat/Dev/golang/fooproject/src/foo (from $GOPATH)这些是文件内容。src/foo/foo.go:package fooimport ( "fmt")func Bar() { fmt.Println("bar")}src/fooer/fooer.go:package mainimport ( "foo")func main() { foo.Bar()}当我尝试这样做时,我遇到了同样的错误go build fooer.go。项目结构哪里出了问题?
1 回答
暮色呼如
TA贡献1853条经验 获得超9个赞
那可能是因为一个错字:
goloang
instead of
golang
你有:
$ echo $GOPATH
/Users/Bharat/Dev/golang/fooproject
^^^^^^
$ pwd
/Users/Bharat/Dev/goloang/fooproject/src/fooer
^^^^^^^
- 1 回答
- 0 关注
- 146 浏览
添加回答
举报
0/150
提交
取消