ctrl-alt-delor
ctrl-alt-delor

Reputation: 7745

go run/build not getting dependencies

go run and go build are not geting dependencies.

What I did:

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?

Upvotes: 3

Views: 9712

Answers (1)

VonC
VonC

Reputation: 1328342

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/....


From the comments:

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.

Upvotes: 1

Related Questions