dosin84644 2019-01-20 14:41
浏览 42
已采纳

去运行/构建没有得到依赖

go run and go build are not geting dependencies.

What I did:

  • I have done a go get of a package, it fetched it, and its dependencies, and build it. (all is good)
  • I run its command-line example program. (all is good)
  • I then created a new program based on this example, and go run it. (all is good)
  • Then copied this example program, and go run it. ( get a dependency error ).

Transcript

#↳ go version
go version go1.11.4 linux/amd64

#↳ echo $GOPATH
/home/????/+Files/workshops/programming/golang/gopath

#↳ go get -u github.com/cbroglie/mustache/...

#↳ cp -T $GOPATH/src/github.com/cbroglie/mustache/cmd/mustache/main.go my-mustache.go

#↳ go build -v my-mustache.go
my-mustache.go:8:2: cannot find package "github.com/spf13/cobra" in any of:
    /usr/local/go/src/github.com/spf13/cobra (from $GOROOT)
    /go/src/github.com/spf13/cobra (from $GOPATH)

I can see why it is not already installed: it was in a vendor sub-directory of the original source code. But why does it not install, when I build?

  • 写回答

1条回答 默认 最新

  • dpicx06888 2019-01-20 15:55
    关注

    Check first your $GOPATH/bin folder: a go get -u github.com/cbroglie/mustache/... should already have compiled and installed all relevant binaries in it.

    The README mentions:

    To install mustache.go, simply run go get github.com/cbroglie/mustache/....


    It looks like the mustache package is installed and working.
    However when I try to build the cli example, it needs another package, if I go get it then all is well, however I was expecting go build to install all needed packages.
    Am I wrong?

    go build itself won't install dependencies, so you need to go get it, or activate go 1.11 modules and declare that dependencies in your new program modules.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境